From: David S. <da...@sa...> - 2009-05-12 03:54:52
|
All, A new snapshot release of JUnit 4.7 is up: https://sourceforge.net/project/showfiles.php?group_id=15278&package_id=226053&release_id=682045 The newest feature in this release is a golden oldie: access to the name of the currently-running test method: @RunWith(Interceptors.class) public class NameInterceptorTest { @Interceptor public TestName name = new TestName(); @Test public void testA() { assertEquals("testA", name.getMethodName()); } } Share and Enjoy, David Saff P.S. The entire release notes: ## Summary of Changes in version 4.7 ## ### Interceptors ### - Interceptors allow very flexible addition or redefinition of the behavior of each test method in a test class. For example, this class will keep a log of each passing and failing test: @RunWith(Interceptors.class) public static class WatchmanTest { private static String watchedLog; @Interceptor public StatementInterceptor watchman= new TestWatchman() { @Override public void failed(Throwable e, FrameworkMethod method) { watchedLog+= method.getName() + " " + e.getClass().getSimpleName() + "\n"; } @Override public void succeeded(FrameworkMethod method) { watchedLog+= method.getName() + " " + "success!\n"; } }; @Test public void fails() { fail(); } @Test public void succeeds() { } } For more on this feature, see http://www.threeriversinstitute.org/blog/?p=155 - The TestName Interceptor makes the current test name available inside test methods: @RunWith(Interceptors.class) public class NameInterceptorTest { @Interceptor public TestName name = new TestName(); @Test public void testA() { assertEquals("testA", name.getMethodName()); } @Test public void testB() { assertEquals("testB", name.getMethodName()); } } - The Timeout Interceptor applies the same timeout to all test methods in a class: @RunWith(Interceptors.class) public static class HasGlobalTimeout { public static String log; @Interceptor public StatementInterceptor globalTimeout = new Timeout(20); @Test public void testInfiniteLoop1() { log+= "ran1"; for(;;) {} } @Test public void testInfiniteLoop2() { log+= "ran2"; for(;;) {} } } ### Timeouts ### - Tests that timeout now show the stack trace of the test thread. ### Docs ### - Javadocs now link to online JDK javadocs (bug 2090230) - Parameterized runner javadocs improved (bug 2186792) - Fixed Javadoc code sample for AfterClass (2126279) - Fixed Javadoc for assertArraysEqual(float[], float[]) ### Bug fixes ### - Fixed: BaseTestRunner.getTest() requires class to extend TestCase (1812200) - Fixed: Suite does not allow for inheritance in annotations (2783118) - Fixed: ParallelComputer skipped tests that took longer than 2 seconds |