A way to log test execution (who is going to run/stop), FYI...
"Oleskandr" <[email protected]>
| Newsgroups | gmane.comp.java.junit.user |
|---|---|
| Message-ID | <[email protected]> |
Our build on Jenkins stuck on some test. Our *large* organisation forbid access to build server...
So I want to find this broken test (seems to be DB related test with using DbUnit).
Firstly I think to run 'sed -i "s=...=...=" *Test.java"' on test sources. But this require to make fake commit to SVN and then revert history back.
After googling I found:
http://stackoverflow.com/questions/473401/get-name-of-currently-executing-test-in-junit-4
http://stackoverflow.com/questions/1069456/how-to-obtain-test-case-name-in-junit-4-at-runtime
http://stackoverflow.com/questions/10222164/junit-4-test-annotation-reports-test-name-as-unknown
So getting run test name is hard task. But I found "listener" keyword so next googling take me:
http://maven.apache.org/surefire/maven-surefire-plugin/examples/junit.html
(Using custom listeners and reporters)
and I end with implementation:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.13</version>
<configuration>
<reportFormat>text</reportFormat>
<trimStackTrace>false</trimStackTrace>
<useFile>false</useFile>
<properties>
<property>
<name>listener</name>
<value>com.company.utils.LogTests</value>
</property>
</properties>
<includes>
<include>com/company/core/**/*Test.java</include>
</includes>
</configuration>
</plugin>
import java.io.*;
import org.junit.runner.Description;
import org.junit.runner.notification.RunListener;
public class LogTests extends RunListener {
static PrintStream out = new PrintStream(new FileOutputStream(FileDescriptor.out));
public void testStarted(Description description) {
out.println("Test started: " + description.getDisplayName());
}
public void testFinished(Description description) {
out.println("Test finished: " + description.getDisplayName());
}
}
Next I add profile to pom.xml and configure build on Jenkins with '-Pjunitlog'.
What is wonderful that JUnit got Listener support not so long time ago (near 4 years ago):
https://github.com/junit-team/junit/tree/r4.7
Are there any other ways to print test method name without putting System.out in each tests?
------------------------------------
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/junit/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://groups.yahoo.com/group/junit/join
(Yahoo! ID required)
<*> To change settings via email:
[email protected]
[email protected]
<*> To unsubscribe from this group, send an email to:
[email protected]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/