I have a JUnit4
test suite and I want to execute it under the JUnit Plug-in Test
run configuration.
It passes successfully when running through the JUnit Test
configuration, but for plug-in conf it fails in different ways.
For example if I use JUnit4TestAdapter
it fails with ClassCastException
, and if I trying to run it only through the @RunWith
annotation it wrotes "No methods found" error. For both implementations I use JUnit4
Test Runner setting inside run configuration.
I use
For first case it seems that Eclipse proceed to use the JUnit3 version when executing the suite. Here it is:
@RunWith(Suite.class)
@SuiteClasses({ DndTest.class })
public class JSTestSuite {
public static Test suite() {
return new JUnit4TestAdapter(JSTestSuite.class);
}
}
And exception is:
java.lang.ClassCastException: junit.framework.JUnit4TestAdapter cannot be cast to junit.framework.Test
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.getTest(RemoteTestRunner.java:403)
While starting the test I have a strange log message in console:
!ENTRY org.eclipse.update.configurator 2017-05-04 17:58:57.279
!MESSAGE Could not install bundle ../../platform/eclipse/plugins/org.eclipse.jdt.junit4.runtime_1.1.600.v20160505-0715.jar No match is available for the required execution environment: J2SE-1.5
I see this lib is on the place, but I can't understand why it failing to be loaded. For JUnit3
Test Runner setting junit3 lib is loaded ok.
There are some bugs related to such issues (like this) but it is really hard to understand what can I do in this case.
For second case I just try to execute simple JUnit4
case without using the JUnit4TestAdapter
, but it can't find any methods.
Reloading of eclipse and renaming of the methods didn't help. What can I do in this case?
I found that there are couple of issues. First I consider one by one to solve the issue.
Issue#1: No match is available for the required execution environment: J2SE-1.5
Issue#2: java.lang.ClassCastException: junit.framework.JUnit4TestAdapter cannot be cast to junit.framework.Test
If you use maven in your project, then you can change pom.xml file as below:
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
Resource Link: Maven "build path specifies execution environment J2SE-1.5", even though I changed it to 1.7
JUnit runner has a dependency on JUnit 3.8. It won't be used but without it, the whole platform can't be initialized. So you need 2 versions like the following
Check you have below plugins
org.eclipse.xtext.xbase.junit
org.junit (3.8.2)
org.junit (4.8.2)
In eclipse, please check in 2 sections.
Properties->Java Build Path->Libraries (tab)
Run Configurations->JUnit->Classpath (tab)
To fix the error make sure you have org.junit 3.8 in the target platform!
All credit goes to A Paul.
https://stackoverflow.com/a/21334162/2293534
Aaron Digulla has commented like below:
Despite the fact that org.eclipse.xtext.junit4 imports org.junit 4.5.0, org.eclipse.xtext.junit (note the missing "4" at the end) seems to have a dependency to JUnit 3.8. After adding the old, outdated JUnit bundle, the plugin tests started.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With