码迷,mamicode.com
首页 > 其他好文 > 详细

Ignoring a Test

时间:2015-07-11 14:55:45      阅读:126      评论:0      收藏:0      [点我收藏+]

标签:

如果我们不想让某个测试失败,我们仅仅想要忽略它,那么我们可以暂时的disable它。

有三种方法来忽略一个测试:

  • 把方法注释掉
  • 删除 @Test 注释
  • 增加 @Ignore注释: @Ignore([ignore reason])

方法一和方法二会导致测试结果不包括该测试。而使用方法三的话,执行完测试之后,我们不仅会知道跑多少测试,失败多少测试,还会知道有多少测试被忽略了。通过在@Ignore内添加字符串参数我们还可以记录该测试被忽略的原因。

  1. import static org.junit.Assert.assertArrayEquals;  
  2. import org.junit.Ignore;  
  3. import org.junit.Test;  
  4.   
  5. public class IgnoreTest {  
  6.   
  7.     @Ignore("testAssertArrayEquals ignore")  
  8.     @Test  
  9.     public void testAssertArrayEquals(){  
  10.         byte[] expected="trial".getBytes();  
  11.         byte[] actual="trial".getBytes();  
  12.         assertArrayEquals("failure-byte arrays not same",expected, actual);  
  13.     }  
  14. }  

测试结果:

Runs:1/1(1 skipped)           Errors:0           Failures:0

Ignoring a Test

标签:

原文地址:http://www.cnblogs.com/miniren/p/4638505.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!