Set TestNG's verbosity level from Maven

2019-05-02 10:12发布

问题:

When I'm running tests I hate staring at a blinking cursor with no idea what's running. To fix this I've added completion messages to all my tests. However I've realized that its a really hacky solution and adds fluff.

Assuming that TestNG's verbosity level prints the test description, how can I set the verbosity level in Maven? Note that I don't have a test.xml file, so if its the only way then I have no idea how to have a test.xml file + Maven's autogenerated test.xml file work together.

回答1:

Since maven-failsafe-plugin version 2.19 the verbosity level can be configured as follow:

<configuration>
      ...
      <properties>
        <property>
          <name>surefire.testng.verbose</name>
          <value>-1</value>
        </property>
      </properties>
      ...
 </configuration>

Note: The verbosity level is 0 to 10, where 10 is most detailed. -1 will put TestNG in debug mode.



回答2:

Surefire lets you invoke TestNG with any command line parameters you like, and TestNG does support a "verbose" command line, so it's probably only a matter of doing something like

<configuration>
  <verbose>true</verbose>
</configuration>


回答3:

Okay... so, you need let testng.xml and pom.xml work togther.

POM.xml

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-failsafe-plugin</artifactId>
    <version>2.12.1</version>
    <executions>
        <execution>
            <id>integration-test</id>
            <goals>
                <goal>integration-test</goal>
            </goals>
            <configuration>
                <includes>
                    <include>**/*IT.java</include>
                    <include>**/*IT.groovy</include>
                </includes>
                <suiteXmlFiles>
                    <suiteXmlFile>testng-asia.xml</suiteXmlFile>
                    <suiteXmlFile>testng-emea.xml</suiteXmlFile>
                    <suiteXmlFile>testng-ny.xml</suiteXmlFile>
                </suiteXmlFiles>
            </configuration>
        </execution>
        <execution>
            <id>verify</id>
            <goals>
                <goal>verify</goal>
            </goals>
        </execution>
    </executions>
</plugin>

Then, set verbose level in testng*.xml

like that

<suite name="TEST Ex" verbose="2" preserve-order="true" >
 <test name="NOTE"  preserve-order="true" >
    <classes>
        <class name="*IT" />
        <class name="*IT"/>
    </classes>
 </test>
</suite>


回答4:

Try verbose level = 10. It doesn't solve the no XML question, but it can give you more information that you seem to need.