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

I managed to build our tests with help of this tutorial, 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?


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 (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"/> 


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 Thursday in Jira

Updates to give you visibility into what's coming in Jira Server and Data Center

Hello, Community! My name is Gosia and I'm a Product Manager on Jira Server and Data Center here at Atlassian. Since 2002 when we launched our public issue tracker, jira.atlass...

267 views 1 10
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