Cucumber-Spring Boot 1.4集成问题

时间:2018-06-12 03:20:35

标签: spring-boot cucumber

我正在开发一个简单的测试应用程序,使用@RunWith和@SpringBootTest Annoations测试Cucumber与spring boot 1.4的集成。下面是我的项目结构的样子。

Project structure

下面是我的Springapplication类:

@SpringBootApplication
public class simpleApp {

    public static void main(String[] args) {

            SpringApplication.run(simpleApp.class, args);
    }

}

以下是我的专题文件:

Feature: Bag functionalities
  Scenario: Putting one thing in the bag
    Given the bag is empty
    When I put 1 potato in the bag
    Then the bag should contain only 1 potato

以下是应该完成整合魔术的主要类:

import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;
import io.koijam.simpleApi.bootstarter.simpleBean;

@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)

public class SpringBootBaseIntegrationTest {

    @Given("^the bag is empty$")
    public void the_bag_is_empty() throws Exception {

    }

    @When("^I put (\\d+) potato in the bag$")
    public void i_put_potato_in_the_bag(int arg1) throws Exception {

    }

    @Then("^the bag should contain only (\\d+) potato$")
    public void the_bag_should_contain_only_potato(int arg1) throws Exception {
       }
}

下面是我的测试跑步者类:

@RunWith(Cucumber.class)
@CucumberOptions(
        features = "src/test/resources/features",
        plugin = {"pretty", "html:target/cucumber"})

public class TestRunner {
}

这是依赖项的pom.xml:

 <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-java</artifactId>
            <version>${cucumber.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-junit</artifactId>
            <version>${cucumber.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-spring</artifactId>
            <version>${cucumber.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>gherkin</artifactId>
            <version>2.12.2</version>
            <scope>test</scope>
        </dependency>

  </dependencies>

以下是我执行的操作:

  1. 右键单击SpringBootBaseIntegrationTest运行BDD测试场景,然后选择run as junit。
  2. 结果:0场景 0步 0m0.991s

    1. 在SpringBootBaseIntegrationTest类中注释Annotations:@ RunWith和@SpringBootTest并右键单击SpringBootBaseIntegrationTest并选择run as junit来运行BDD测试场景。
    2. 结果:BDD测试成功执行。

      有人可以告诉我在添加注释时没有执行任何场景的#1出了什么问题。

      很抱歉很长的帖子:)

0 个答案:

没有答案