1

I'm working on a multi-module maven project using Java 8, Spring Boot 2.4.0. I want to test one of a module that is calling a 3rd party service. I'm using wiremock to mock that 3rd party service call and have created a spring boot integration test class. My class is in the same package where my XYZService class is. My test is in src/test/... and looks like this.

@RunWith(SpringRunner.class)
@SpringBootTest(classes = SpringApplicationClassWithMainMethod.class)
public class XYZServiceIntegrationTest {

@Rule
public WireMockRule externalService = new WireMockRule();

@Test
public void test1() {...}

@Test
public void test2() {...}
}

When I run the maven build in my eclipse (clean + install). My build is not detecting the tests present at the maven-module where the Integration test is located. The other unit tests in the same module are also not being detected (Note: before adding the integration test class, the unit tests were working). Maven says Tests ran: 0. The integration test is working fine when I Right click on the file and run as JUnit test(Junit 4). Also, I have some environment variables that need to be set for running the SpringApplicationClassWithMainMethod.class that I'm setting within the configurations of that Integration test class in order to successfully load the Application context(I tried to load the environment variables through code and nothing from other stack-overflow posts worked). One more thing to inform my maven only uses Maven surefire plugin for running tests. I dont know if we need to have Maven fail safe plugin for my purpose(Is my test considered a Integration Test when I added the 2 annotations on top of the test class?). Can someone please help me with any suggestions on how to build the parent project.

7
  • Which Spring Boot Version do you use? Commented Mar 2, 2021 at 23:21
  • I'm using Spring boot 2.4.0 Commented Mar 2, 2021 at 23:23
  • Then you should use JUnit Jupiter (aka JUnit 5) instead of JUnit 4 otherwise you need to add the junit-vintage-engine to run your JUnit 4 tests.. Commented Mar 2, 2021 at 23:28
  • I'm using JUnit4 as power Mockito only supports JUnit4 as of now. Also, My JUnit4 tests were running properly before when I used to run maven clean & maven install. Only after I added the above XYZServiceIntegrationTest class none of the tests are being run during Maven build(clean + install). Commented Mar 2, 2021 at 23:39
  • can you add the <build> part of your pom.xml? Commented Mar 3, 2021 at 6:46

1 Answer 1

-1

Adding the maven-failsafe-plugin into my child pom worked. In the parent pom I added the execution goals for maven-failsafe-plugin in the and in the child pom I inherited that plugin.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.