在jenkins中运行单个maven testng文件

时间:2018-06-02 07:54:42

标签: maven jenkins

我是初学者。需要知道如何在Jenkins中运行Maven单个testng文件。

我尝试使用

<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>

它在Maven中运行良好,但在Jenkins中运行不正常。詹金斯显示以下错误,

[INFO] --- maven-compiler-plugin:3.7.0:compile (default-compile) @ FrontOffice ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 4 source files to E:\Security Testing\Luna Workspace\FrontOffice\target\classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] /E:/Security Testing/Luna Workspace/FrontOffice/src/main/java/BaseClass/RetryAnalyzer.java:[3,18] package org.testng does not exist
[ERROR] /E:/Security Testing/Luna Workspace/FrontOffice/src/main/java/BaseClass/RetryAnalyzer.java:[4,18] package org.testng does not exist
[ERROR] /E:/Security Testing/Luna Workspace/FrontOffice/src/main/java/BaseClass/RetryAnalyzer.java:[6,39] cannot find symbol
  symbol: class IRetryAnalyzer
[ERROR] /E:/Security Testing/Luna Workspace/FrontOffice/src/main/java/BaseClass/RetryAnalyzer.java:[10,32] cannot find symbol
  symbol:   class ITestResult

我的POM文件:

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.7.0</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.19.1</version>
                <configuration>
                    <suiteXmlFiles>
                        <suiteXmlFile>testng.xml</suiteXmlFile>
                    </suiteXmlFiles>
                </configuration>
            </plugin>
        </plugins>
    </build>

最好的方法是什么?

2 个答案:

答案 0 :(得分:0)

将Test NG添加到构建依赖项中。

答案 1 :(得分:0)

好的,你已经创建了surefire插件,现在你必须创建一个maven作业,并在目标下的Build部分添加

clean test -Dsurefire.suiteXmlFiles=/path/to/testng.xml

但是为了确保它能够正常工作,请先在命令行中尝试:

mvn clean test -Dsurefire.suiteXmlFiles=/path/to/testng.xml

在Jenkins中删除“mvn”关键字,不需要它。

希望它有所帮助,