Spring Download - My Unit Tests Skipped

I am migrating an existing project for download. I created a completely new project using start.spring.io and copied the source code, etc. Everything compiles, but when I run the "mvn test", it compiles the classes, but then only the "ApplicationTests" by default (created by running .spring.io).

Here is an excerpt from the maven output:

[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ pendview --- [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] skip non existing resourceDirectory C:\dev\pendview2\src\test\resources [INFO] [INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ pendview --- [INFO] Changes detected - recompiling the module! [INFO] Compiling 26 source files to C:\dev\pendview2\target\test-classes [INFO] [INFO] --- maven-surefire-plugin:2.15:test (default-test) @ pendview --- [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ 

What's even weirder, if I pass '-Dtest = TestAuthController' then it runs this particular unit test:

  [INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ pendview --- [INFO] Changes detected - recompiling the module! [INFO] Compiling 26 source files to C:\dev\pendview2\target\test-classes [INFO] [INFO] --- maven-surefire-plugin:2.15:test (default-test) @ pendview --- [INFO] Surefire report directory: C:\dev\pendview2\target\surefire-reports (skipped output of AuthControllerTest for brevity) ------------------------------------------------------- TESTS -------------------------------------------------------Results : Tests run: 6, Failures: 0, Errors: 0, Skipped: 0 

What am I doing wrong? Does spring load the configuration with confidence that I disagree?

Any help would be greatly appreciated! -Trey

+7
java spring spring-boot spring-mvc maven
source share
4 answers

Spring Boot configures the Surefire plugin to run all test classes with a name ending in Test or Tests , but not starting with Abstract . You can see this configuration in spring-boot-starter-parent pom . If your test class is named TestAuthController , then it does not match this configuration. Renaming it to AuthControllerTest or AuthControllerTests should fix your problem.

+12
source share

There seems to be some problem with the Maven surefire plugin when it does not detect tests if your test class name does not end with the Tests suffix. surefire

+1
source share

Try this command in console / terminal:

mvn clean install

But first go to your test directory. If you do not want to run the test, use this command:

mvn clean install -Dmaven.test.skip

+1
source share

It seems Andy's answer should be updated for Spring Boot 2.X. I can’t see the config at any time. There are probably too many complaints about this convention.

0
source share

All Articles