Using custom reporters with the maven surefire plugin

为君一笑 提交于 2019-12-19 11:23:08

问题


I'm trying to use a custom reporter for TestNG with the maven surefire plugin. I already have a custom listener and that seems to get picked up. However, it doesn't look like the custom reporter is being used at all:

<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>

Any idea why this is happening?


回答1:


I figured this out. It looked like the following doesn't work at all:

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

in spite of documentation to the contrary. In the TestNG class it appears that there is a method called TestNG#addListener(IReporter listener), which contrary to its name, accepts a report which implements IReporter. Maven Surefire (v2.12.1) calls this method to add listeners and reports. However, it doesn't look for reports under a property with name reporter. Instead, you have to add your custom reporter to the listener property:

<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>

Not very intuitive.



来源:https://stackoverflow.com/questions/11835790/using-custom-reporters-with-the-maven-surefire-plugin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!