0

I have a test

package ...

...
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.springframework.beans.factory.annotation.Autowired;
...

import static org.junit.jupiter.api.Assertions.*;

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class WebLayerTest {

    @Test
    public void testSomething() throws ... {

        ...

and I can run in from Jetbrains IDEA well. Unfortunately, it doesn't work from Maven

mvn test

just doesn't run it, while

mvn test -Dtest=WebLayerTest

swears

[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  5.557 s
[INFO] Finished at: 2022-05-11T13:07:11+03:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.21.0:test (default-test) on project app: No tests were executed!  (Set -DfailIfNoTests=false to ignore this error.) -> [Help 1]

Maven version is

> mvn --version
Apache Maven 3.8.4 (9b656c72d54e5bacbed989b64718c159fe39b537)
Maven home: D:\Users\myname\apache-maven-3.8.4
Java version: 17.0.2, vendor: Azul Systems, Inc., runtime: D:\Users\myname\.jdks\azul-17.0.2
Default locale: en_US, platform encoding: Cp1252
OS name: "windows server 2016", version: "10.0", arch: "amd64", family: "windows"
Dims
  • 47,675
  • 117
  • 331
  • 600
  • Isn't this related https://stackoverflow.com/questions/36970384/surefire-is-not-picking-up-junit-5-tests? So I guess it has nothing to do with Spring Boot but rather that surefire is not picking up your junit5 test. Try to update your surefire plugin to 2.22.x+. – Balázs Németh May 11 '22 at 10:30
  • 2
    maven-surefire-plugin 3.0.0-M6 works with JUnit 5 – XtremeBaumer May 11 '22 at 10:32
  • Does this answer your question? [Surefire is not picking up Junit 5 tests](https://stackoverflow.com/questions/36970384/surefire-is-not-picking-up-junit-5-tests) – Balázs Németh May 11 '22 at 10:33
  • Upgrade surefire plugin to 3.0.0-M6... – khmarbaise May 11 '22 at 10:39

0 Answers0