javaspringspring-mvcjunitspringjunit4classrunner

maven does not detect tests from the command line


I have a Spring MVC project (an application framework and inversion of control container for the Java platform) with this test:

@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
@ContextConfiguration(locations = {
        "classpath:servlet.xml"
})
public class PastisControllerTests {

    @Autowired
    private WebApplicationContext wac;

    private MockMvc mockMvc;

    @Before
    public void setup() {

        this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build();
    }

    @Test
    public void should_WhenParams_OK() throws Exception {

        mockMvc.perform(get("/user/2")
                .param("date", "01122020")
                .param("organisationId", "9")
                .contentType(APPLICATION_JSON))
                .andExpect(status().isOk());
    }
..
}

but when I run mvn test from the command line, no test is executed


Solution

  • The problem is here: PastisControllerTests Test, not Tests, is the name component you need for Maven to recognize it out of the box. Otherwise, you need to override the surefire plugin's behavior.