3

I'm running TestNG tests via maven using: mvn test or mvn test -Dtest=<Class-Name> or mvn test -Dgroups=<groups...>.

There are a lot of output arriving from the tests that I want to store in files, but the console output I need is like:

TestA.test1 - Passed
TestA.test2 - Failed
TestB.test11 - Passed

I implemented a listener that implements ITestListener and put System.out.println(message); with suitable messages for each method. In the pom.xml I added a plugin:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.9</version>
    <configuration>
        <properties>
            <property>
                <name>listener</name>
                <value><my listener full name class></value>
            </property>
        </properties>
    </configuration>
</plugin>

But nothing seems to respond, and the same output keeps coming to the console.

Any idea what am I doing wrong here? I want to keep running my tests via mvn test but change the output to be more organized.

1 Answer 1

1

If you want that listener to work for every test, you are importing in the test classes wrong. Your pom.xml should be like this:

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.21.0</version>
            <configuration>
                <properties>
                    <property>
                        <name>usedefaultlisteners</name>
                        <value>false</value>
                    </property>
                    <property>
                        <name>listener</name>
                        <value>org.uncommons.reportng.HTMLReporter, org.uncommons.reportng.JUnitXMLReporter
                        </value>
                    </property>
                </properties>
            </configuration>
        </plugin>

You should disable the default listeners to use custom listeners.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.