简体   繁体   English

从黄瓜中的功能生成java测试类

[英]Generate java test class from features in cucumber

I am new to cucumber and wanted to understand if there is any plugin to generate java test class code from a cucumber feature file. 我是黄瓜的新手,想要了解是否有任何插件可以从黄瓜功能文件生成java测试类代码。

Example : I have the below scenario - 
  Scenario: Determine past date
    Given today is 2011-01-20
    When I ask if Jan 19, 2011 is in the past
    Then the result should be yes

Is there a way to generate test class with the methods for each? 有没有办法用每种方法生成测试类? I am just looking to generate the skeleton of the class so that it speeds up the development process. 我只是想生成类的骨架,以便加快开发过程。

You can run the feature with a runner class like: 您可以使用以下运行程序类运行该功能:

import org.junit.runner.RunWith;

import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;

@RunWith(Cucumber.class)
@CucumberOptions(
dryRun = false,
strict = true,
plugin = {"pretty"},
features = {"path/to/features"},
glue = {"package.of.steps"},
tags = {"@TagsToRun"})

public class MyCucumberTestRunnner {
    public MyCucumberTestRunnner() {
    }
}

This can be executed as JUnit Test and Cucumber will tell you, that there are missing steps and will provide you the Step Skeletons. 这可以作为JUnit Test执行,Cucumber会告诉你,缺少步骤并会为你提供Step Skeletons。

if the glue code is in the same package you dont need to provide the information 如果胶水代码在同一个包装中,则您不需要提供信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM