Uriko
Uriko

Reputation: 31

change the console output when running testng tests via maven

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.

Upvotes: 3

Views: 1154

Answers (1)

Kristijan Rusu
Kristijan Rusu

Reputation: 567

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.

Upvotes: 1

Related Questions