- Вы должны предоставить небольшой пример, который другие могут использовать для воспроизведения вашей проблемы
Посмотрите на этот небольшой фрагмент, который работает
Предположим, следующая структура
pom.xml
src/test/java/TestRunner.java
src/test/java/stepdefs/StepDefinitions.java
src/test/java/stepdefs/Hooks.java
src/test/resource/features/demo.feature
pom.xml
...
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.target>1.8</maven.compiler.target>
<version.cucumber>4.2.0</version.cucumber>
</properties>
<dependencies>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>${version.cucumber}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>${version.cucumber}</version>
<scope>test</scope>
</dependency>
</dependencies>
...
TestRunner.java
import org.junit.runner.RunWith;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
@RunWith(Cucumber.class)
@CucumberOptions(
features = {"src/test/resource/features"},
glue = {"stepdefs"}
)
public class TestRunner {
}
StepDefinitions.java
package stepdefs;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;
public class StepDefinitions {
@Given("^a successful step$")
public void aSuccessfulStep() {
System.out.println(" aSuccessfulStep()");
}
@When("doing something")
public void doingSomething() {
System.out.println(" doingSomething()");
}
@Then("something happen")
public void somethingHappen() {
System.out.println(" somethingHappen()");
}
}
Hooks.java
package stepdefs;
import cucumber.api.java.After;
import cucumber.api.java.AfterStep;
import cucumber.api.java.Before;
import cucumber.api.java.BeforeStep;
public class Hooks {
@Before
public void init() {
System.out.println("@Before scenario");
}
@After
public void cleanUp() {
System.out.println("@After scenario");
}
@BeforeStep
public void beforeStep() {
System.out.println(" @BeforeStep");
}
@AfterStep
public void afterStep() {
System.out.println(" @AfterStep");
}
}
demo.feature
Feature: Test cucumber reporting plugin
Scenario: Run a non failing scenario
Given a successful step
When doing something
Then something happen
работаетtests
$ mvn clean test
производит следующий вывод
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running TestRunner
@Before scenario
@BeforeStep
aSuccessfulStep()
@AfterStep
@BeforeStep
doingSomething()
@AfterStep
@BeforeStep
somethingHappen()
@AfterStep
@After scenario
1 Scenarios (1 passed)
3 Steps (3 passed)