【问题标题】:Can't run test from Maven in TeamCity with testNG and Allure无法使用 testNG 和 Allure 从 TeamCity 中的 Maven 运行测试
【发布时间】:2016-12-13 06:37:44
【问题描述】:

我正在尝试通过 Maven 在 TeamCity 中运行我的 testClass。我有这个错误 -

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.19.1:test (default-test) on project PGRegression: Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:2.19.1:test failed: There was an error in the forked process java.lang.NoSuchMethodError: ru.yandex.qatools.allure.events.TestSuiteStartedEvent.withTitle(Ljava/lang/String;)Lru/yandex/qatools/allure/events/TestSuiteStartedEvent;

我在 TeamCity 中的 buildSteps 目标 -

clean
test -Dtest=testClass verify

我在这里使用 pom 示例 - https://github.com/allure-framework/allure-core/wiki/TestNG

<build>
<plugins>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.14</version>
        <configuration>
            <testFailureIgnore>false</testFailureIgnore>
            <argLine>
                -javaagent:${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar
            </argLine>
            <!--only for 1.3.* TestNG adapters. Since 1.4.0.RC4, the listener adds via ServiceLoader-->
            <properties>
                <property>
                    <name>listener</name>
                    <value>ru.yandex.qatools.allure.testng.AllureTestListener</value>
                </property>
            </properties>
        </configuration>
        <dependencies>
            <dependency>
                <groupId>org.aspectj</groupId>
                <artifactId>aspectjweaver</artifactId>
                <version>${aspectj.version}</version>
            </dependency>
        </dependencies>
    </plugin>
</plugins>

如果我在没有 yandex allure 的情况下运行另一个 testClass - 它工作得很好而且我没有这个错误。我在我的 pom 中使用诱惑这个 -

    <properties>
    <aspectj.version>1.8.9</aspectj.version>
    <allure.version>1.4.23</allure.version>
    <!--<allure.version>{latest-allure-version}</allure.version>-->
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
    <dependency>
        <groupId>ru.yandex.qatools.allure</groupId>
        <artifactId>allure-testng-adaptor</artifactId>
        <version>${allure.version}</version>
    </dependency>
    <dependency>
        <groupId>ru.yandex.qatools.allure</groupId>
        <artifactId>allure-model</artifactId>
        <version>1.4.23</version>
    </dependency>
    <dependency>
        <groupId>ru.yandex.qatools.allure</groupId>
        <artifactId>allure-maven-plugin</artifactId>
        <version>2.5</version>
    </dependency>
    <dependency>
        <groupId>ru.yandex.qatools.allure</groupId>
        <artifactId>allure-java-commons</artifactId>
        <version>1.3.9</version>
    </dependency>
    <dependency>
        <groupId>ru.yandex.qatools.allure</groupId>
        <artifactId>allure-java-annotations</artifactId>
        <version>1.4.23</version>
    </dependency>

【问题讨论】:

    标签: maven maven-surefire-plugin allure yandex


    【解决方案1】:

    您正在使用不同主要版本的 Allure 工件:

    您正在使用 Allure Commons 1.3.9:

    <dependency>
        <groupId>ru.yandex.qatools.allure</groupId>
        <artifactId>allure-java-commons</artifactId>
        <version>1.3.9</version>
    </dependency>
    

    这里我们有 1.4.23。

    <dependency>
        <groupId>ru.yandex.qatools.allure</groupId>
        <artifactId>allure-java-annotations</artifactId>
        <version>1.4.23</version>
    </dependency>
    

    这就是你得到 NoSuchMethodError 的原因。请不要这样做。而是简单地依赖 allure-testng 依赖:

    <dependency>
            <groupId>ru.yandex.qatools.allure</groupId>
            <artifactId>allure-testng-adaptor</artifactId>
            <version>${allure.version}</version>
            <exclusions>
                <exclusion>
                    <groupId>junit</groupId>
                    <artifactId>junit</artifactId>
                </exclusion>
            </exclusions>
    </dependency>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-02-20
      • 2018-01-31
      • 1970-01-01
      • 2017-01-09
      • 2019-05-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多