Re: A way to log test execution (who is going to run/stop), FYI...
David Saff <[email protected]>
| Newsgroups | gmane.comp.java.junit.user |
|---|---|
| Message-ID | <CALrw-PzLA7gkc84p357CrNuEbwbk80kovj2K3oJb9Up2f_Xq=A@mail.gmail.com> |
Oleskandr, Sorry for the late reply. You may be best off with a Rule for displaying the method names. http://stackoverflow.com/questions/473401/get-name-of-currently-executing-test-in-junit-4 might be a starting point. Good luck, David On Fri, Feb 22, 2013 at 8:32 AM, Oleskandr <[email protected]> wrote: > > > 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: > > > org.apache.maven.plugins > maven-surefire-plugin > 2.13 > > text > false > false > > > listener > com.company.utils.LogTests > > > > com/company/core/**/*Test.java > > > > > 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/