在其他项目中重用Cucumber-JVM步骤定义 [英] Reusing Cucumber-JVM step definitions in other projects

查看:89
本文介绍了在其他项目中重用Cucumber-JVM步骤定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在其他项目中重用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



中看到以下内容 * some_content *

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

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?

推荐答案

解。看起来很容易。

有@CucumberOptions批注,其参数为胶水。将此参数指向具有步骤定义的基本包,将强制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步骤定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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