开发者

How could i get a Testname / Test status in JUnit

I am new to JUnit . I am working on the ways to get a output like

classname / function name / status / description.

I figured that there is no other way to get success test name other than FrameworkMethod using Rule. Is it possible to set a Rule to a suite which s running with the help of JUnitCore/textui.Thx in advance.!!

Edit:- I tried testwatchman with Junit 4.9b2 but executing suites is not working for me. Any help would be appreciated.


@RunWith(Suite.class) 
@SuiteClasses({testclass1.class, testclass2.class}) 
public class junitCheck {
     开发者_运维问答private static String watchedLog;

     @Rule
     public MethodRule 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";
             }
     };

}

public class testclass1 {

    @Test
    public void add()
    {
        Assert.assertEquals(4,2+3);
    }
}

public class testclass2 {


    @Test
    public void add1()
    {
        Assert.assertEquals(4,2+2);
    }
}


Have a look at the TestWatchman rule.


It won't work with the suite. So the only way is to add an org.junit.rules.TestWatcher to a common super class of the tests.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜