Tuesday, 18 August 2015

[Java] failed to run individual test within a class for JUnit



I have many individual testes to test a specific class using JUnit. During development, I am just focusing on one individual test only and so for example, I just want to run testCompoundProc0 only.




One way to do is "Junit Test" under "Run As/Debug As" by selecting the test and clicking right button.



But for latest CZT built with Java 8 and Maven 3.2.5 on Eclipse (Mars), there is an error.

java.lang.NoSuchMethodError: org.junit.runner.Description.getClassName()Ljava/lang/String;
    at org.eclipse.jdt.internal.junit4.runner.DescriptionMatcher$LeadingIdentifierMatcher.matches(DescriptionMatcher.java:95)
    at org.eclipse.jdt.internal.junit4.runner.DescriptionMatcher$CompositeMatcher.matches(DescriptionMatcher.java:38)
    at org.eclipse.jdt.internal.junit4.runner.SubForestFilter.collectIncludedDescriptions(SubForestFilter.java:49)
    at org.eclipse.jdt.internal.junit4.runner.SubForestFilter.apply(SubForestFilter.java:41)
    at org.junit.internal.requests.FilterRequest.getRunner(FilterRequest.java:35)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createFilteredTest(JUnit4TestLoader.java:77)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:68)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:43)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:444)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
 So I guest it may be due to the problem of JUnit version used. At first, find out which version is used in CZT. Check "czt-code/pom.xml" or in Eclipse, "Project" -> "Properties" -> "Java build path" -> "Libraries" -> "Maven Dependencies".  So JUnit 4.5 is used.


Try to use another version, "$ls ~/.m2/repository/junit/junit/" and found there is a latest 4.8.1 version. Go to "Project" -> "Properties" -> "Java build path" -> "Libraries" -> "Add External JARs" and choose "~/.m2/repository/junit/junit/4.8.1/junit-4.8.1.jar". 

Then tried again and it succeeds to run one individual test once.

1 comment :