How to get junit tests execution reports

1,403 views
Skip to first unread message

Curt Patrick

unread,
Jan 25, 2016, 8:19:52 PM1/25/16
to bazel-discuss
Hello,

I am trying to generate test/coverage reports with my Bazel CI builds using the Jenkins Sonar plugin.  I figured out how to run Jacoco with the unit tests (add -jacocoagent to the javaflags in the java_test rule).  But Sonar (and maybe jacoco as well?) expects junit tests execution reports to be available.  Everything I read tells me how to generate those using maven or ant, but I wanted to use those I wouldn't be using Bazel.  Can someone recommend a Bazel consistent way to do this?

Curt

Brian Silverman

unread,
Jan 25, 2016, 9:30:36 PM1/25/16
to Curt Patrick, bazel-discuss
I think Bazel already generates those. 39125b (recently) added support for copying those out of the sandbox so you can do something with them afterwards.

If you need a list of the execution reports, `bazel query` and a bit of post-transformation should work. There might be a better way too; I'm not sure.

--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/2ced18dc-f3c8-4f09-8711-c334b93cb3d5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Damien Martin-guillerez

unread,
Jan 26, 2016, 2:40:06 AM1/26/16
to Brian Silverman, Curt Patrick, bazel-discuss

With bazel at HEAD you need to use the '--nolegacy_bazel_java_test' flag to use our recently shipped test runner and get XML reports.


Curt Patrick

unread,
Jan 27, 2016, 6:38:46 PM1/27/16
to bazel-discuss, bsilve...@gmail.com, michaelcur...@gmail.com
Thanks for the feedback.  I have taken that as far as I can on my own, but I still don't find anything that looks like "execution reports" in my build tree.  Here is what I did:

- I built the tip of the Bazel sources and ran my tests with the option you recommended.  For the record, my BUILD rule looks like this:
--------------------------------------------------------------------

java_test(

    name = "lock_coverage",

    srcs = glob(["**/*.java"]),

    size = "small",

    deps = [

        "//java/com/shn/base/io/lock:lock",

        "@junit//jar",

        "@truth//jar",

    ],

    test_class = "com.shn.base.io.lock.FileLockTest",

    runtime_deps = [

        "@hamcrest-core//jar",

    ],

    jvm_flags = ["-javaagent:/shn/builder/workspace/build-io-lock/EngProd/buildtools/jacoco_agents/0.7.5/jacocoagent.jar=destfile=/shn/builder/workspace/build-io-lock/target/jacoco.exec"]
------------------------------------------------------------ 

And the Bazel command looks like this:
----------------------------------------------------

/Users/curt/projects/git/github/bazelbuild/bazel/output/bazel test --nolegacy_bazel_java_test  //javatest/com/shn/base/io/lock:lock_coverage

----------------------------------------------------


Questions:
--------------
* With the no-legacy option I had to add the test_class setting in the rule to get it to work without erroring out.  Does that mean I'm going to have to add a test rule for every test class in the project?

* The output says "Executed 1 out of 1 tests: 1 test passes."  This looks quite suspicious as there are 6 or 8 tests in the test class com.shn.base.io.lock.FileLockTest.  Does this imply that I'm not really running any tests?  But I am getting no feedback that helps me figure out what is going on.

* I didn't see anything in the bazel query language that would help find the test reports.  The documentation says "you use bazel query to analyze build dependencies."  I am missing how that is relevant to finding test results?

* If they were being generated, what exactly do "execution reports" look like?

I apologize if I am being dense but, with other build tools I've used, I just plug in a plugin and everything about generating reports happens "magically".  I've never had to get under the hood before, and am not finding much documentation for educating myself.

Curt
Reply all
Reply to author
Forward
0 new messages