无法 运行 在 TeamCity 中使用 testNG 和 Allure 从 Maven 进行测试

Can't run test from Maven in TeamCity with testNG and Allure

我正在尝试通过 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>

您正在使用不同主要版本的 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>