Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Clover instrumented tests with JUnit @Parameterized are failing with NoClassDefFound: junit/runner/TestRunListener

Deleted user November 12, 2015

I managed to build our tests with help of this tutorial https://confluence.atlassian.com/display/CLOVER/Using+Clover+with+Maven+Tycho+Plugin, coverage data is generated, but there is one small problem:

All tests that are being run with @Parameterized annotation are failing with

java.lang.NoClassDefFound: junit/runner/TestRunListener

 

From what I've found so far the exception is comming from JUnitParameterizedTestSniffer that is injected by clover.

Do you have any idea how to fix this?

2 answers

0 votes
Deleted user November 26, 2015

Finally I've solved this problem using this piece of code after instrumentation:

<replace dir="${project.instrumented.dir}" token="new com_atlassian_clover.JUnitParameterizedTestSniffer()" value="com_atlassian_clover.TestNameSniffer.NULL_INSTANCE"> 
	<include name="**/*.java"/> 
</replace>

 

Maybe it is not the prettiest solution - but it works just fine.

0 votes
Marek Parfianowicz
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
November 12, 2015

Hi Ola,

If Clover detects JUnit parameterized test, it adds an extra static field which is being used to record test iterations. The JUnitParameterizedTestSniffer uses junit.runner.TestRunListener, which is a class from the JUnit JAR. Normally, it should work out of the box, as if you're running a JUnit test you also must have a junit.jar in a classpath.

1) Could you please tell us what version of JUnit do you use?

2) Do you have junit.jar in the test classpath when running tests?

Cheers
Marek 

Deleted user November 13, 2015

Hi Marek,

 

I forgot to mention what versions we are using, sorry for that. We're using maven3, tycho 0.22, junit 4.11.

I am pretty sure that junit is in the classpath. When I run mvn clean install -e -X in our tests directory I have this in logs:

[DEBUG] Using test framework provider org.eclipse.tycho.surefire.provider.impl.JUnit4Provider 
[DEBUG] Installation OSGI bundles: 
...

[DEBUG]     reference:file:C:/Users/User/.m2/repository/p2/osgi/bundle/org.junit/4.11.0.v201303080030/org.junit-4.11.0.v201303080030.jar 

...

I've also tried to push junit in using -Xbootclasspath/a: but with no luck.

 

Only thing that comes to my mind is that clover is using different class loader somehow.

 

Grzegorz Lewandowski
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
November 17, 2015

I think it's highly probable that JUnit and Clover are loaded by different class loaders (Clover from basic bootstrap, JUnit by OSGI Class loader) If you add JUnit to boot classpath you'll probably end up with 2 Junit libraries in the JVM and it's not working well as-well. Have you tried simply adding Clover as an maven dependency to test module? I suspect {{-Xbootclasspath}} won't be necessary in that case.

Marek Parfianowicz
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
November 17, 2015

Feel free to raise a ticket at support.atlassian.com (providing build logs, build files etc).

Deleted user November 17, 2015

@Grzegorz Lewandowski Yes, tried that, nothing changed. Do you know any way to force clover into same class loader? I guess that if every test bundle has dependency to clover (transformed into osgi bundle) it might work. I will try that tomorrow. @Marek Parfianowicz If I don't succeed I will raise a ticket for sure! I will try to make some kind of smallest "working" example.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events