首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 开源软件 >

junit单元测试中几个有用的注脚

2013-03-27 
junit单元测试中几个有用的注解单元测试代码质量之必备,junit4中有几个有用但是不常用的注解。前序:public

junit单元测试中几个有用的注解

单元测试代码质量之必备,junit4中有几个有用但是不常用的注解。

前序:

public abstract class StringUtilsExt {public static boolean isEmpty(String str) {return StringUtils.isEmpty(str);}public static boolean is(String str) {if (StringUtils.isNotEmpty(str)) {throw new RuntimeException();}return true;}}

?@Ignore:就是忽略此代码的执行

@Ignorepublic final void test() {StringUtilsExt.is(null);}

?

@Test(expected=RuntimeException.class):此单元测试期待有RuntimeException的异常

@Test(expected=RuntimeException.class)public final void testIs() {StringUtilsExt.is(null);}

?@Test(timeout=1):此代码执行如果超过指定的时间那么执行不通过

@Test(timeout=1)public final void testIsEmpty() {String str=null;try {        Thread.sleep(10);        } catch (InterruptedException e) {        e.printStackTrace();        }        Assert.assertTrue(StringUtilsExt.isEmpty(str));}

?

?

热点排行