Reputation: 30934
I have a larger number of tests and want (triggered via maven) see on stdout/stderr, which test method is currently executed.
I do not want or need that inside the test itself, but rather follow what is going on -- a little bit like IntelliJ does that with the circles that then turn red or green.
Is there a command line option to do this, or do I have to write my own test runner, which does that for me?
Upvotes: 4
Views: 2543
Reputation: 1764
What Matthew wrote works for JUnit and TestNG has a similar interface also.
I'm using TestNG, and setting the verbosity high does the job for me:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
<configuration>
<properties>
<property>
<name>surefire.testng.verbose</name>
<value>10</value>
</property>
</properties>
</configuration>
</plugin>
</plugins>
</build>
It is documented here http://maven.apache.org/surefire/maven-surefire-plugin/examples/testng.html
The verbosity level is between 0 and 10 where 10 is the most detailed. You can specify -1 and this will put TestNG in debug mode (no longer slicing off stack traces and all). The default level is 0.
It has also been answered here Set TestNG's verbosity level from Maven
The output then contains such lines as the tests progress:
[TestNG] INVOKING: "Surefire test" - org.example.MyTest.myMethod(java.lang.String, java.lang.String)(value(s) ...
Also the @BeforeClass and @AfterClass methods are mentioned.
Upvotes: 3
Reputation: 61695
Your best option is probably a RunListener, which you can plug into Maven:
RunListener
listens to test events, such as test start, test end, test failure, test success etc.
public class RunListener {
public void testRunStarted(Description description) throws Exception {}
public void testRunFinished(Result result) throws Exception {}
public void testStarted(Description description) throws Exception {}
public void testFinished(Description description) throws Exception {}
public void testFailure(Failure failure) throws Exception {}
public void testAssumptionFailure(Failure failure) {}
public void testIgnored(Description description) throws Exception {}
}
Then, in surefire, you can specify a custom listener, using:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.10</version>
<configuration>
<properties>
<property>
<name>listener</name>
<value>com.mycompany.MyResultListener,com.mycompany.MyResultListener2</value>
</property>
</configuration>
</plugin>
This is from Maven Surefire Plugin, Using JUnit, Using custom listeners and reporters
Upvotes: 4