I am using Maven 3.6.1, JDK 1.8, JUnit 5.6.0 and JUnit platform 1.6.0. I exclude the dependency on junit:junit from spring-boot-starter-test, so that I have no JUnit 4 artifacts left in the dependency tree. Note that both Spring Boot 2.2 and 2.3 use maven-surefire-plugin 2.22.2, so my problem does not originate from any regression of the maven-surefire-plugin.
This error occurs if the project excludes or not include JUnit 4 when it depends on spring-boot-starter-test. The spring-boot-starter-test depends on junit-vintage-engine by default. To resolve this issue either we have to exclude junit-vintage-engine Or should not depend on spring-boot-starter-test.
Similar issue can be observed for "junit-jupiter" test engine, in case of running tests located inside java9 named modules (also for Spring Boot app). The message is the same without clue about the reason:
In case anyone is still having this issue, the above did not work for me. My solution involved using the latest spring boot test dependency, and then including the class name in the spring boot test annotation as shown below. I removed all my previous junit exclusions and explicit dependencies.
The JUnit Platform serves as a foundation for launching testingframeworks on the JVM. It also defines the TestEngine API for developing a testingframework that runs on the platform. Furthermore, the platform provides aConsole Launcher to launch the platform from thecommand line and the JUnit Platform Suite Engine for running a custom test suite usingone or more test engines on the platform. First-class support for the JUnit Platform alsoexists in popular IDEs (see IntelliJ IDEA,Eclipse, NetBeans, andVisual Studio Code) and build tools (see Gradle,Maven, and Ant).
JUnit Jupiter is the combination of the programming model andextension model for writing tests and extensions in JUnit 5. The Jupitersub-project provides a TestEngine for running Jupiter based tests on the platform.
any instance method that is directly annotated or meta-annotated with@Test, @RepeatedTest, @ParameterizedTest, @TestFactory, or @TestTemplate.With the exception of @Test, these create a container in the test tree that groupstests or, potentially (for @TestFactory), other containers.
Test methods and lifecycle methods may be declared locally within the current test class,inherited from superclasses, or inherited from interfaces (seeTest Interfaces and Default Methods). In addition, test methods andlifecycle methods must not be abstract and must not return a value (except @TestFactorymethods which are required to return a value).
The following test class demonstrates the use of @Test methods and all supportedlifecycle methods. For further information on runtime semantics, seeTest Execution Order andWrapping Behavior of Callbacks.
You can use the junit.jupiter.displayname.generator.defaultconfiguration parameter to specify the fully qualifiedclass name of the DisplayNameGenerator you would like to use by default. Just like fordisplay name generators configured via the @DisplayNameGeneration annotation, thesupplied class has to implement the DisplayNameGenerator interface. The default displayname generator will be used for all tests unless the @DisplayNameGeneration annotationis present on an enclosing test class or test interface. Values provided via@DisplayName annotations always take precedence over display names generated by aDisplayNameGenerator.
For example, to use the ReplaceUnderscores display name generator by default, you shouldset the configuration parameter to the corresponding fully qualified class name (e.g., insrc/test/resources/junit-platform.properties):
Even though the assertion facilities provided by JUnit Jupiter are sufficient for manytesting scenarios, there are times when more power and additional functionality such asmatchers are desired or required. In such cases, the JUnit team recommends the use ofthird-party assertion libraries such as AssertJ, Hamcrest, Truth, etc. Developersare therefore free to use the assertion library of their choice.
The following example demonstrates how to use the assertThat() support from Hamcrest ina JUnit Jupiter test. As long as the Hamcrest library has been added to the classpath,you can statically import methods such as assertThat(), is(), and equalTo() andthen use them in tests like in the assertWithHamcrestMatcher() method below.
The ExecutionCondition extension API in JUnit Jupiter allowsdevelopers to either enable or disable a container or test based on certainconditions programmatically. The simplest example of such a condition is the built-inDisabledCondition which supports the @Disabled annotation (seeDisabling Tests). In addition to @Disabled, JUnit Jupiter also supportsseveral other annotation-based conditions in the org.junit.jupiter.api.conditionpackage that allow developers to enable or disable containers and tests declaratively.When multiple ExecutionCondition extensions are registered, a container or test isdisabled as soon as one of the conditions returns disabled. If you wish to providedetails about why they might be disabled, every annotation associated with these built-inconditions has a disabledReason attribute available for that purpose.
Unless otherwise stated, each of the conditional annotations listed in the followingsections can only be declared once on a given test interface, test class, or test method.If a conditional annotation is directly present, indirectly present, or meta-presentmultiple times on a given element, only the first such annotation discovered by JUnit willbe used; any additional declarations will be silently ignored. Note, however, that eachconditional annotation may be used in conjunction with other conditional annotations inthe org.junit.jupiter.api.condition package.
A container or test may be enabled or disabled on particular versions of the JavaRuntime Environment (JRE) via the @EnabledOnJre and @DisabledOnJre annotationsor on a particular range of versions of the JRE via the @EnabledForJreRange and@DisabledForJreRange annotations. The range defaults to JRE.JAVA_8 as the lowerborder (min) and JRE.OTHER as the higher border (max), which allows usage ofhalf open ranges.
A container or test may be enabled or disabled within aGraalVM native image via the@EnabledInNativeImage and @DisabledInNativeImage annotations. These annotations aretypically used when running tests within a native image using the Gradle and Mavenplug-ins from the GraalVM NativeBuild Tools project.
A container or test may be enabled or disabled based on the value of the named JVMsystem property via the @EnabledIfSystemProperty and @DisabledIfSystemPropertyannotations. The value supplied via the matches attribute will be interpreted as aregular expression.
As of JUnit Jupiter 5.6, @EnabledIfSystemProperty and @DisabledIfSystemProperty arerepeatable annotations. Consequently, these annotations may be declared multiple timeson a test interface, test class, or test method. Specifically, these annotations will befound if they are directly present, indirectly present, or meta-present on a given element.
A container or test may be enabled or disabled based on the value of the namedenvironment variable from the underlying operating system via the@EnabledIfEnvironmentVariable and @DisabledIfEnvironmentVariable annotations. Thevalue supplied via the matches attribute will be interpreted as a regular expression.
As of JUnit Jupiter 5.6, @EnabledIfEnvironmentVariable and@DisabledIfEnvironmentVariable are repeatable annotations. Consequently, theseannotations may be declared multiple times on a test interface, test class, or testmethod. Specifically, these annotations will be found if they are directly present,indirectly present, or meta-present on a given element.
As an alternative to implementing an ExecutionCondition, acontainer or test may be enabled or disabled based on a condition method configured viathe @EnabledIf and @DisabledIf annotations. A condition method must have a booleanreturn type and may accept either no arguments or a single ExtensionContext argument.
For example, java.awt.GraphicsEnvironment provides a public static boolean isHeadless()method that can be used to determine if the current environment does not support agraphical display. Thus, if you have a test that depends on graphical support you candisable it when such support is unavailable as follows.
Test classes and methods can be tagged via the @Tag annotation. Those tags can later beused to filter test discovery and execution. Please refer to theTags section for more information about tag support in the JUnitPlatform.
By default, test classes and methods will be ordered using an algorithm that isdeterministic but intentionally nonobvious. This ensures that subsequent runs of a testsuite execute test classes and test methods in the same order, thereby allowing forrepeatable builds.
To control the order in which test methods are executed, annotate your test class or testinterface with @TestMethodOrder and specify the desired MethodOrdererimplementation. You can implement your own custom MethodOrderer or use one of thefollowing built-in MethodOrderer implementations.
You can use the junit.jupiter.testmethod.order.default configuration parameter to specify the fully qualified class name of theMethodOrderer you would like to use by default. Just like for the orderer configuredvia the @TestMethodOrder annotation, the supplied class has to implement theMethodOrderer interface. The default orderer will be used for all tests unless the@TestMethodOrder annotation is present on an enclosing test class or test interface.
For example, to use the MethodOrderer.OrderAnnotation method orderer by default, youshould set the configuration parameter to the corresponding fully qualified class name(e.g., in src/test/resources/junit-platform.properties):
Although test classes typically should not rely on the order in which they are executed,there are times when it is desirable to enforce a specific test class execution order. Youmay wish to execute test classes in a random order to ensure there are no accidentaldependencies between test classes, or you may wish to order test classes to optimize buildtime as outlined in the following scenarios.
aa06259810