1

I have a maven project (multimodule, JDK 11) that has a lot of modules and tests within it.

I suddenly noticed that one of my tests is NOT invoked as part of the surefire plugin. Other tests in the same module do get to be invoked successfully. I am able to run this test successfully via Intellij. The test is not disabled nor ignored. it contains a set of @Test methods. In addition, I am able to run it specifically using mvn test -Dtest=... argument.

The test class gets to be compiled successfully and appears in target/test-classes. (I have already run with -X and could not find relevant additional data there)

I am working with surefire plugin 2.22.1 ; junit-vintage-engine:5.2.0 ; junit-platform-runner:1.2.0 ; Spring Boot 2.5.3 (with BOM) ; My test is spring based and invoked using @ExtendWith(SpringExtension.class) (I do have other spring based tests that are invoked as expected though).

Following this question, I have also tried to work with 2.22.2. It did not solve the problem

Following this question, I have verified and indeed all tests in the test class that does not invoke are prefixed with the 'test' word

EDIT: The problem happens in a test that belongs to a module that is part of a larger project in my company, which inherits various defaults across the POM inheritance chain. Unfortunately, I can not isolate only my POM out of it and present it. I have tried to reproduce the problem in a new isolated project but did not succeed (that is, all the tests were invoked as expected).

What am I missing? Is there a hidden switch of the surefire plugin that reveals what's going on under the hood and where do surefire pull the list of tests he is meant to execute?

aviad cohen
  • 637
  • 1
  • 6
  • 16
  • 1
    Try the classic method of "remove all until the error disappears and then return one step before". Leave there only one test which performs and one which does not. And **then** show us your complete code, stripped from all the irrelevant parts (like the details of the tests etc., leave there just `System.out.println("test performed")`). – Honza Zidek Nov 04 '21 at 09:30
  • Can you post your pom.xml. Maybe something is going on there ... like here http://maven.apache.org/surefire/maven-surefire-plugin/examples/inclusion-exclusion.html – Arthur Klezovich Nov 04 '21 at 09:36
  • Also, what happens if you try and rename the test ? – Arthur Klezovich Nov 04 '21 at 09:37
  • Which Spring/Spring Boot version do you use? Furthermore do you use spring boot parent? Or do you use BOM's? Depending on the version of spring only JUnit 5.X is supported than using junit-vintage does not make sense... – khmarbaise Nov 04 '21 at 11:09
  • 2
    Check the name of your Testclass. By default surefire only executes: ...Test.java, Test....java, ...Tests.java and ...TestCase.java – Kathrin Geilmann Nov 04 '21 at 12:42
  • @HonzaZidek: I am trying that in the meantime, but I have over 200 tests across more than 100 test files so... it's not that easy :) – aviad cohen Nov 04 '21 at 12:49
  • @ArthurKlezovich: I have edited the post regarding your comment. I am having trouble following that path – aviad cohen Nov 04 '21 at 12:53
  • @khmarbaise: I have added in the post the spring boot version (2.5.3). Not sure I followed your recommendation regarding junit-vintage? – aviad cohen Nov 04 '21 at 12:53
  • Try adding the following keys when running mvn test ... -X,--debug,-e,--errors this will print a detailed debug log ... and you will see if your test is included into tests which the framework wants to run – Arthur Klezovich Nov 04 '21 at 12:57
  • @KathrinGeilmann That was the problem! Thank you! I had no idea that these are the rules according to which SureFire selects the tests. (if you can point to documentation of that I will appreciate) The name of my test ended with ...Tester.java – aviad cohen Nov 04 '21 at 12:57
  • What exactly is being ignored ? The whole module or individual test files ? – Arthur Klezovich Nov 04 '21 at 12:57

2 Answers2

1

The surefire plugin (by default) will run only tests with the following name syntax ...

"**/Test*.java" - includes all of its subdirectories and all Java filenames that start with "Test".
"**/*Test.java" - includes all of its subdirectories and all Java filenames that end with "Test".
"**/*Tests.java" - includes all of its subdirectories and all Java filenames that end with "Tests".
"**/*TestCase.java" - includes all of its subdirectories and all Java filenames that end with "TestCase".

More details can be found here

Arthur Klezovich
  • 2,595
  • 1
  • 13
  • 17
0

Problem solved! Following @Kathrin Geilmann comment:

...By default surefire only executes: ...Test.java, Test....java, ...Tests.java and ...TestCase.java

The name of my file ended with ...Tester (!@#$$%^)

Thanks.

aviad cohen
  • 637
  • 1
  • 6
  • 16