Java test failed to start

Junit5 with IntelliJ and Gradle

Trying to migrate my project to java8 + Junit5 using IntelliJ 2017.2

I have added junit-jupiter-api version 5.0.0-M6 and junit-platform-launcher version 1.0.0-M6 Project structure is a default maven convention src/test/java Found a couple articles about this but none of them did solve my issue. It runs nicely in a console, I presume this is something to do with the IntelliJ default JUnit Runner, or I am missing some dependencies? When I Run a single test class all works fine but when I select the directory and Run all ‘Tests’ in Java like I used to do then I encounter few errors.

WARNING: TestEngine with ID 'junit-jupiter' failed to discover tests java.lang.NoSuchMethodError: org.junit.platform.engine.TestDescriptor.pruneTree()V Aug 02, 2017 2:44:56 PM org.junit.platform.launcher.core.DefaultLauncher handleThrowable WARNING: TestEngine with ID 'junit-vintage' failed to discover tests java.lang.NoSuchMethodError: org.junit.platform.engine.EngineDiscoveryRequest.getDiscoveryFiltersByType(Ljava/lang/Class;)Ljava/util/List; Aug 02, 2017 2:44:56 PM org.junit.platform.launcher.core.DefaultLauncher handleThrowable WARNING: TestEngine with ID 'junit-jupiter' failed to discover tests java.lang.NoSuchMethodError: org.junit.platform.engine.TestDescriptor.pruneTree()V Aug 02, 2017 2:44:56 PM org.junit.platform.launcher.core.DefaultLauncher handleThrowable WARNING: TestEngine with ID 'junit-vintage' failed to discover tests java.lang.NoSuchMethodError: org.junit.platform.engine.EngineDiscoveryRequest.getDiscoveryFiltersByType(Ljava/lang/Class;)Ljava/util/List; 

Источник

Error running Spring boot tests in IntelliJ Community 2017.1

This is a very weird behavior. I have a Spring boot application which works fine. Since a couple of days (I just switched the app to another Git repo, if it means something) every time I run tests with IntelliJ I gest the error:

java.lang.IllegalStateException: Failed to load ApplicationContext at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:124) at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:83) at org.springframework.test.context.web.ServletTestExecutionListener.setUpRequestContextIfNecessary(ServletTestExecutionListener.java:189) at org.springframework.test.context.web.ServletTestExecutionListener.prepareTestInstance(ServletTestExecutionListener.java:131) at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:230) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:228) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:287) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:289) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:247) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:94) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61) at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:191) at org.junit.runner.JUnitCore.run(JUnitCore.java:137) at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68) at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51) at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242) at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70) Caused by: java.lang.IllegalStateException: Failed to add PropertySource to Environment at org.springframework.test.context.support.TestPropertySourceUtils.addPropertiesFilesToEnvironment(TestPropertySourceUtils.java:198) at org.springframework.boot.test.context.SpringBootContextLoader.loadContext(SpringBootContextLoader.java:100) at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:98) at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:116) . 24 common frames omitted Caused by: java.io.FileNotFoundException: class path resource [com/mycompany/myproject/test.properties] cannot be opened because it does not exist at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:172) at org.springframework.core.io.support.EncodedResource.getInputStream(EncodedResource.java:154) at org.springframework.core.io.support.PropertiesLoaderUtils.fillProperties(PropertiesLoaderUtils.java:98) at org.springframework.core.io.support.PropertiesLoaderUtils.fillProperties(PropertiesLoaderUtils.java:72) at org.springframework.core.io.support.PropertiesLoaderUtils.loadProperties(PropertiesLoaderUtils.java:58) at org.springframework.core.io.support.ResourcePropertySource.(ResourcePropertySource.java:84) at org.springframework.test.context.support.TestPropertySourceUtils.addPropertiesFilesToEnvironment(TestPropertySourceUtils.java:194) . 27 common frames omitted 09:54:42.723 [main] DEBUG org.springframework.test.context.support.AbstractDirtiesContextTestExecutionListener — After test class: context [DefaultTestContext@371a67ec testClass = AudioVideoControllerTest, testInstance = [null], testMethod = [null], testException = [null], mergedContextConfiguration = [WebMergedContextConfiguration@5ed828d testClass = AudioVideoControllerTest, locations = ‘<>‘, classes = », contextInitializerClasses = ‘[]’, activeProfiles = ‘<>‘, propertySourceLocations = », propertySourceProperties = », contextCustomizers = set[org.springframework.boot.test.context.SpringBootTestContextCustomizer@548e7350, org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@77cd7a0, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@754ba872, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@0, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizerFactory$Customizer@13805618], resourceBasePath = ‘src/main/webapp’, contextLoader = ‘org.springframework.boot.test.context.SpringBootContextLoader’, parent = [null]]], class annotated with @DirtiesContext [false] with mode [null]. Process finished with exit code -1

@RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = MyApplication.class) @TestPropertySource(locations="test.properties") @SpringBootTest public class AudioVideoControllerTest

The file is in the classpath (src/main/java/com/mycompany/myproject/test.properties) Now the weirdest part. If I open the project with Eclipse (Sprig Tool Suite actually) and I run tests, they work. Then I run again tests on IntelliJ and. they work! So it looks like Eclipse/STS makes some changes when I open and refresh the project but I wonder what it is.

Читайте также:  Html button svg css

Источник

Intellij does not run tests

After importing my project into Intellij and getting it to build successfully, I am trying to run some of my project’s tests. I navigate to the test file and select Run -> Run. However, this does not run my tests, just opens a small «Edit Configurations» window, as the attached photo shows. enter image description here And, when I select Edit Configurations as prompted, JUnit is not to be found. The window is shown below. enter image description here What do I need to do to run the tests?

Please review this SO post. I’m guessing your IntelliJ cannot find the JUnit JAR, and this is why it is not appearing in the drop down (it appears in mine).

Right click on the test class name either in the code window or in the project panel, and select Run . If you don’t see the run menu in the popup then you haven’t selected a test or you don’t have junit plugin installed.

4 Answers 4

For me it was also an issue with my pom.xml. After checking Junit5-samples pom. I noticed the test plugin was missing. So I only needed to add:

You may also want to check if your pom contains:

 org.junit.jupiter junit-jupiter 5.6.2 test  

For me this was an issue with my pom.xml and using JUnit5 with IntelliJ because my tests were not getting detected and it said 0 executed 0 skipped etc.

Here’s what I added to my pom.xml to get JUnit5 tests to run in IntelliJ :

    org.apache.maven.plugins maven-surefire-plugin 2.21.0  org.junit.platform junit-platform-surefire-provider 1.2.0-M1  org.junit.jupiter junit-jupiter-engine 5.2.0      

And here’s the dependencies I added:

   org.junit.jupiter junit-jupiter-api 5.2.0 test  org.easytesting fest-assert-core 2.0M10 test  org.junit.platform junit-platform-surefire-provider 1.2.0-M1  org.junit.jupiter junit-jupiter-engine 5.2.0-M1   

Источник

Junit 5.5.1 and 5.5.2 suddenly failing to run tests: «Process finished with exit code -1»; 5.6.0-RC1 is missing a class

I added Junit 5.5.1 to a project that otherwise uses 4.11. I’ve written tests that, until today, were running just fine. Today all the tests were failing with exit code -1 even before any of the test class was executed. I’m not aware of any dependencies changing that would cause this. I switched to 5.6.0-RC1, which seemed to be missing an extension class (TestInstancePreDestroyCallback). I then tried noticed 5.5.2 and switched to it: it had the same problem as 5.5.1. I gave 5.6.0-RC1 one more try — this time I noticed that the jar was named 5.6.0-M1. This version worked, so I seem to be okay, but that was an unsettling and not-confidence-inspiring sequence of events. My question is: has this happened to anyone else, and what exactly was it? Update: Turns out the class missing in 5.6.0-M1 is present in 5.6.0-RC1, so I’ve switched to it. I’m not pursuing the 5.5.* problems any further.

Please show your dependencies (Gradle or Maven files) as well as the exact error message you get. At first glance it’s more likely to be a compile/build problem than a JUnit one.

I’m afraid my company considers dependencies proprietary. But here are details on the 5.6.0 issue: java.lang.NoClassDefFoundError: org/junit/jupiter/api/extension/TestInstancePreDestroyCallback It’s not in the M1 jar: $ jar tf junit-jupiter-api-5.6.0-M1.jar | grep «api/extension/TestInstance» org/junit/jupiter/api/extension/TestInstanceFactory.class org/junit/jupiter/api/extension/TestInstances.class org/junit/jupiter/api/extension/TestInstanceFactoryContext.class org/junit/jupiter/api/extension/TestInstancePostProcessor.class but it is present in 5.6.0-RC1.

Since 5.6.0-RC1 is working for me, I will not pursue the 5.5.* sudden abort problem and I would recommend updating to the release candidate.

Источник

Оцените статью