0

I am implementing some algorithm which generate junit test cases and best case will be chosen based on code coverage. workflow is for each public method generate some random test cases, execute them sequentially, pick best case based on coverage of that testcase. Is there any library which can provide me coverage numbers by API call and after every testcase I can reset coverage numbers so that I can get coverage numbers for next testcase only.

1 Answer 1

1

jacoco can do that when you control the runtime.

In that case, you will eventually create a RuntimeData instance to be passed to the IRuntime. RuntimeData has a reset() method and you can query it for coverage information.

Sign up to request clarification or add additional context in comments.

6 Comments

Thanks a lot for the answer, I am trying jacoco library and referring to eclemma.org/jacoco/trunk/doc/examples/java/CoreTutorial.java . I have modified my testcase and instrumented the source class in setup method and startup the IRuntime. then I am loading target class using custom class loader. now the problem is in my testcases I am getting classcast exception because of different class loader. line on which I am getting exception looks like MyTargetClass app = (MyTargetClass) targetClass.newInstance(); can I skip custom class loader part and use system class loader
There is no simple answer to this. You need to figure out which classes should be loaded by which classloader and then make sure this really happens.
I got it working by using reflection but I am curious to know is it possible to load class by custom class loader using "MyTargetClass app = xxxxxx" statement
Use Class<?> appClass = customClassLoader.loadClass("com.foo.MyTargetClass");
If you want to invoke methods of a class that comes from a different class loader, then you must use reflection. There is no way to cast classes between classloaders; they are always different.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.