I am trying JUnit 5 and Cucumber at Spring Boot 2.2.6 and will need both BDD scenarios and unit tests at my application. I have created a dummy ping controller corresponding feature file which are OK.
Cucumber tests are not called when I run mvn clean test. Only JUnit test is called. However, I can run Cucumber scenarios from Intellij GUI when click on the Run Test button for CucumberTest.java.
Here are my classes:
DummyApplicationTests.java:
package com.a.dummy;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
@SpringBootTest
@ActiveProfiles("test")
public class DummyApplicationTests {
@Test
public void contextLoads() {
}
}
CucumberTest.java:
package com.a.dummy.bdd;
import io.cucumber.junit.Cucumber;
import io.cucumber.junit.CucumberOptions;
import org.junit.runner.RunWith;
@RunWith(Cucumber.class)
@CucumberOptions(features = "src/test/resources/features")
public class CucumberTest {
}
CucumberSpringContextConfiguration.java:
package com.a.dummy.bdd;
import com.a.dummy.DummyApplication;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.ContextConfiguration;
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@ActiveProfiles("test")
@ContextConfiguration(classes = DummyApplication.class)
public abstract class CucumberSpringContextConfiguration {
}
PingTest.java:
package com.a.dummy.bdd.steps;
import com.a.dummy.bdd.CucumberSpringContextConfiguration;
import io.cucumber.java.en.And;
import io.cucumber.java.en.Then;
import io.cucumber.java.en.When;
public class PingTest extends CucumberSpringContextConfiguration {
@When("^the client calls /ping")
public void the_client_issues_GET_ping() {
...
}
@Then("^the client receives status code of (\\d+)$")
public void the_client_receives_status_code_of(int statusCode) {
...
}
@And("^the client receives ping response")
public void the_client_receives_ping_response_body() {
...
}
}
What I am missing?