Myeclipse中如何進行JUnit單元測試?(3)
發表于:2016-10-28來源:冷血之心的博客作者:冷血之心點擊數:
標簽:MyEclipse
testAddNum () {Test1 ts= new Test1();ts.addNum( 3 , 6 );} @After public void testm2 () {Test1 ts= new Test1();ts.method2();} @Ignore public void testm3 () {Test1 ts= new Test1();ts.method3();} @Before
testAddNum(){
Test1 ts=
new Test1();
ts.addNum(
3,
6);
}
@After
public void testm2(){
Test1 ts=
new Test1();
ts.method2();
}
@Ignore
public void testm3(){
Test1 ts=
new Test1();
ts.method3();
}
@Before
public void testm4(){
Test1 ts=
new Test1();
ts.method4();
}
}
如何運行?
方法1:在測試方法類中,我們可以選中某個方法比如testm3,選擇Run as ---->JUint Test
方法2:將整個測試類運行,選擇Run as ---->JUint Test
結果如何?

如圖出現綠條說明方法測試成功。
按照上邊的代碼,在Console中將出現如下結果:

即標有Ignore的測試方法沒有被執行,Before和After方法分別在Test方法之前和之后執行了一次。
原文轉自:http://blog.csdn.net/qq_25827845/article/details/52132596