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 > On 9. Jul 2023, at 23:36, Ellen Spertus <[email protected]> wrote: > > 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 > <https://github.com/jacoco/jacoco/blob/master/org.jacoco.examples/src/org/jacoco/examples/CoreTutorial.java>, > 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 > <https://github.com/espertus/jacquard/compare/jacoco1...jacoco2?diff=split> > between the two versions are minimal. (The reason I put them in different > branches is so it is easy to see the diff > <https://github.com/espertus/jacquard/compare/jacoco1...jacoco2?diff=split> > 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 > > -- > 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 [email protected] > <mailto:[email protected]>. > To view this discussion on the web visit > https://groups.google.com/d/msgid/jacoco/4505015c-e5e9-4ea0-b04e-efb58fc90111n%40googlegroups.com > > <https://groups.google.com/d/msgid/jacoco/4505015c-e5e9-4ea0-b04e-efb58fc90111n%40googlegroups.com?utm_medium=email&utm_source=footer>. -- 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 [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/jacoco/831EF877-17FF-41A3-97FA-8967A1F585EE%40mountainminds.com.
