Having difficulty adapting CoreTutorial to split TestTarget

21 views
Skip to first unread message

Ellen Spertus

unread,
Jul 9, 2023, 5:36:15 PM7/9/23
to JaCoCo and EclEmma Users
I am writing an autograder and will need to be able to measure the coverage of tests provided by a student. To use the  JaCoCo Java API, I am working with the provided CoreTutorial, which has a Runnable inner class TestTarget, containing two methods: run() and isPrime(). The code instruments the class, then calls the  run() method. (I'm omitting some details.) It works, reporting partial coverage. This is in branch jacoco1 of my repo.

I created another branch jacoco2 that splits TestTarget into two classes: ClassUnderTest (which has isPrime()) and TestClass (which has run()).  It compilies and runs without throwing any exceptions, but it does not report any coverage. The differences between the two versions are minimal. (The reason I put them in different branches is so it is easy to see the diff on GitHub.)

Could anyone tell me what I am doing wrong and how to correctly adapt CoreTutorial to involve multiple classes, where one calls the other?

I've appended additional the output of each program.

Thank you.

Ellen

Output of run on jacoco1 (original CoreTutorial)

Coverage of class com/spertus/jacquard/coverage/CoreTutorial$TestTarget
2 of 25 instructions missed
1 of 4 branches missed
1 of 7 lines missed
0 of 3 methods missed
1 of 5 complexity missed
Line 40: green
Line 41:
Line 42:
Line 43: green
Line 44: green
Line 45:
Line 46:
Line 47: green
Line 48: yellow
Line 49: red
Line 50:
Line 51:
Line 52: green


Output of run on jacoco2 (split CoreTutorial)

Coverage of class com/spertus/jacquard/coverage/CoreTutorial$ClassUnderTest
20 of 20 instructions missed
4 of 4 branches missed
5 of 5 lines missed
2 of 2 methods missed
4 of 4 complexity missed
Line 53: red
Line 54:
Line 55: red
Line 56: red
Line 57: red
Line 58:
Line 59:
Line 60: red

Marc Hoffmann

unread,
Jul 11, 2023, 8:20:12 AM7/11/23
to JaCoCo and EclEmma Users
Hi Ellen,

the problem is with class loading: You load TestClass with the regular application class loader. It will not delegate to the MemoryClassLoader. Therefore the instrumented version will never be loaded.

To resolve this TestClass must also be added to the MemoryClassLoader and loaded from there.

Regards,
-marc


--
You received this message because you are subscribed to the Google Groups "JaCoCo and EclEmma Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jacoco+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jacoco/4505015c-e5e9-4ea0-b04e-efb58fc90111n%40googlegroups.com.

Ellen Spertus

unread,
Jul 11, 2023, 1:55:44 PM7/11/23
to jac...@googlegroups.com
Thank you so much! That worked.

Marc Hoffmann

unread,
Jul 13, 2023, 12:41:13 PM7/13/23
to jac...@googlegroups.com
Good to hear!

Regards,
-marc

On 11. Jul 2023, at 19:55, Ellen Spertus <ellen....@gmail.com> wrote:

Thank you so much! That worked.

--
You received this message because you are subscribed to the Google Groups "JaCoCo and EclEmma Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jacoco+un...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages