maven - 将自定义记者与 maven surefire 插件一起使用

标签 maven testng surefire

我正在尝试通过 maven surefire 插件为 TestNG 使用自定义报告程序。我已经有一个自定义监听器,它似乎被选中了。但是,看起来根本没有使用自定义报告程序:

<plugin>
    <artifactId>maven-surefire-plugin</artifactId>
    <configuration>
        <testFailureIgnore>false</testFailureIgnore>
        <properties>
            <property>
                <name>listener</name>
                <value>com.mystuff.test.TestNGListener</value>
            </property>
            <property>
                <name>reporter</name>
                <value>com.mystuff.test.MyEmailableReporter</value>
            </property>
        </properties>
    </configuration>
</plugin>

知道为什么会这样吗?

最佳答案

我想通了。看起来以下内容根本不起作用:

<property>
    <name>reporter</name>
    <value>com.mystuff.test.MyEmailableReporter</value>
</property>

尽管有相反的文件。在 TestNG 类中似乎有一个名为 TestNG#addListener(IReporter listener) 的方法,与其名称相反,它接受实现 IReporter< 的报告。 Maven Surefire (v2.12.1) 调用此方法来添加监听器和报告。但是,它不会在名称为 reporter 的属性下查找报告。相反,您必须将自定义报告程序添加到 listener 属性:

<plugin>
    <artifactId>maven-surefire-plugin</artifactId>
    <configuration>
        <testFailureIgnore>false</testFailureIgnore>
        <properties>
            <property>
                <name>listener</name>
                <value>com.mystuff.test.TestNGListener,com.mystuff.test.MyEmailableReporter</value>
            </property>
        </properties>
    </configuration>
</plugin>

不是很直观。

关于maven - 将自定义记者与 maven surefire 插件一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11835790/

相关文章:

eclipse - 如何确定 m2e 减慢 eclipse 构建速度的原因?

gradle - gradle测试任务的执行顺序

java - 执行 org.apache.maven.plugins :maven-surefire-plugin:2. 14.1:test: org/junit/runner/notification/RunListener 时缺少必需的类

java - 防止PMD二次打印违规

java - 将一个 Maven 项目添加到另一个 Maven 项目中导致无法解析依赖项错误

testng - 将Selenium,TestNG和ReportNG与Gradle结合使用

java - 当范围标记为 'test' 时导入 testng 类

java - 如何将 maven-surefire-plugin 执行拆分为两个单独的执行?

eclipse - Maven "Module"与 "Project"(Eclipse、m2eclipse 插件)