首页 文章

将Cucumber Java项目转换为Maven项目并在Jenkins中运行

提问于
浏览
0

我已将我的java项目(使用黄瓜框架构建)转换为Maven Project . 我无法使用Sure Fire插件,因为我的文件夹结构不是这种格式“src / test / java”

我的文件夹结构是testng xml,包含了黄瓜转轮文件的信息,现在我的目标是在jenkins中触发这个testng xml .

我知道从命令提示符执行testng xml,但要做到这一点,我们需要有lib文件夹 . 由于我使用Maven,我没有本地lib文件夹 . 有人可以建议,在这种情况下该怎么办? (不想更改文件夹结构)

提前致谢

1 回答

  • 2

    首先,通过在pom文件中添加 <dependency> 条目,为CLASSPATH引入所需的依赖项 .

    简而言之,您需要添加至少以下的内容

    <!-- https://mvnrepository.com/artifact/info.cukes/cucumber-testng -->
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-testng</artifactId>
        <version>1.2.5</version>
        <exclusions>
            <!-- ignoring older version of testng -->
            <exclusion>
                <groupId>org.testng</groupId>
                <artifactId>testng</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.testng/testng -->
    <dependency>
        <groupId>org.testng</groupId>
        <artifactId>testng</artifactId>
        <version>6.11</version>
        <!-- Remove the scope tag, if you have some TestNG listener code residing in src/main/java -->
        <scope>test</scope>
    </dependency>
    

    现在添加以下条目以告诉Maven测试类所在的位置以及测试资源所在的位置 .

    <build>
        <!-- test sources represents the folder where in your classes that contain @Test methods reside-->
        <testSourceDirectory></testSourceDirectory>
        <!-- test resources represents the folder which contains your .feature files, your .suite xml etc-->
        <testResources></testResources>
    </build>
    

    有关如何调整surefire插件行为的更多详细信息,请参阅here .

相关问题