cucumber-jvm步骤定义java [英] cucumber-jvm step definition java

查看:144
本文介绍了cucumber-jvm步骤定义java的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在其他项目中重用Cucumber-JVM步骤定义来测试一些典型的Web操作。关键是我已经创建了一些Java项目,只是使用典型场景操作的步骤定义实现,如:

How can I reuse Cucumber-JVM Step Definitions in other projects to test some typical web actions. The point is that I've created some java project just with Step Definition Implementations of the typical scenario actions like:

When I follow the link "*some_link*"
Then I should see following content "*some_content*" on page

我想在其他项目中重用这些定义(包括在类路径中),只是为了编写自己的简单场景。但是当我运行场景(作为JUnit测试)时,Cucumber无法找到步骤定义。当我尝试扩展Step Definitions类时,它给了我一个错误,我无法扩展Step Definition类。
那么,是否有可能重用步骤定义,如果是这样的话?

And I want to reuse these definitions in other projects(include in classpath), just to write their own simple scenarios. But when I run the scenario (as JUnit test), Cucumber cant find Step Definitions. And when I try to extend Step Definitions class it gives me an error, that I can't extent Step Definition class. So, is it possible to reuse Step Definitions and if so than how?

推荐答案

好吧,我找到了解。看起来很容易。

Well, I've found solution. It appears quite easy.

@CucumberOptions注释有参数glue。将此参数指向具有步骤定义的基础包会强制Cucumber在该基础包中进行搜索。测试运行器将如下所示:

There is annotation @CucumberOptions which has parameter "glue". Pointing with this parameter to the base package that has the step definitions forces Cucumber to search in that base package. The test runner will look like:

@RunWith(Cucumber.class)
@CucumberOptions(glue = { "com.example.stepdefspackage" })
public class Run{
}

这篇关于cucumber-jvm步骤定义java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆