Java 依赖项jar中的Cucumber步骤定义

Java 依赖项jar中的Cucumber步骤定义,java,eclipse,maven,cucumber,cucumber-junit,Java,Eclipse,Maven,Cucumber,Cucumber Junit,我有多个项目在不同的项目中使用类似的步骤定义。因此,在单个项目中使用所有步骤定义,并在maven中添加为依赖项jar。 当我使用maven命令运行时,它会显示: 您可以使用以下代码段实现缺少的步骤: @When("^Import a canvas from \"(.*?)\" to project \"(.*?)\"$") public void import_a_canvas_from_to_project(String arg1, String arg2) throws Throwable

我有多个项目在不同的项目中使用类似的步骤定义。因此,在单个项目中使用所有步骤定义,并在maven中添加为依赖项jar。 当我使用maven命令运行时,它会显示:

您可以使用以下代码段实现缺少的步骤:

@When("^Import a canvas from \"(.*?)\" to project \"(.*?)\"$")
public void import_a_canvas_from_to_project(String arg1, String arg2) throws Throwable {
 // Write code here that turns the phrase above into concrete actions
  throw new PendingException();
  }
但当我在同一个项目中添加包时,效果很好。(即使在eclipse中,也可以从不同的项目工作)。有没有办法从maven和jenkins那里运行这样的场景

我正在使用EclipseIDE。我使用的maven命令是: mvn-DprofileTest=黄瓜清洁-P黄瓜试验

cucumberID是我的个人资料名称

我在pom.xml中添加了以下配置文件

<profile>
<id>cucumberID</id>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <version>2.11</version>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <testFailureIgnore>true</testFailureIgnore>
                    <includes>
                                <include>step_definitions/LoginTest.java</include>
                    </includes>
                    <parallel>classes</parallel>
                    <threadCount>3</threadCount>
                    <useFile>true</useFile>
                </configuration>
            </plugin>
        </plugins>
    </build>
</profile>

黄瓜
org.apache.maven.plugins
2.11
maven surefire插件
真的
步骤u定义/LoginTest.java
班级
3.
真的

您尚未指定如何运行测试套件,但假设您在某个地方有
@CucumberOptions
,您可以直接指向其他项目包,如下所示:

@CucumberOptions(. . . glue = {
        "com.company.test.package1", "com.company2.test.package2", . . .})

使用包名的classpath:前缀来解决此问题。

例如:

@CucumberOptions(glue={“classpath:com.example.test.steps”})

如果您将使用Maven首选的创建软件包的方式,则“mvn package”您的代码,并“mvn install”此软件包,然后,您就可以从外部库运行测试,而不必更改用
@CucumberOptions

注释的类。问题在于glue选项,因为stepdefinition是作为jar依赖项添加的不同项目的一部分。@RunWith(Cucumber.class)@cucucumberOptions(features=“classpath:features”,glue={“com.xurmo.bdd.stepdefinition.ui”},plugin={“pretty”,“html:target/cucumber html report”},tags={})公共类RunCukesTest{}我想你需要将这个包添加到你的项目中。这是cucumber scanner的一个限制吗?@Komal对不起,我搞错了。我把功能文件的位置搞错了。修复了我的答案。