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

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

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 

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.

 

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.

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

@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.

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.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published yesterday in Jira Ops

Jira Ops Early Access Program Update #1: Announcing our next feature and a new integration

Thanks for signing up for Jira Ops! I’m Matt Ryall, leader for the Jira Ops product team at Atlassian. Since this is a brand new product, we’ll be delivering improvements quickly and sharing updates...

182 views 0 5
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you