读书人

Junit上Debug调试与直接使用Run As的J

发布时间: 2012-11-08 08:48:12 作者: rapoo

Junit下Debug调试与直接使用Run As的Junit Test测试的结果差异
使用java.util.regex包下面的方法,用Junit运行与调试发现一些问题,希望各位高手解释下:

代码示例如下:

public void replaceChange(){
Pattern p = Pattern.compile("cat");
Matcher m = p.matcher("one cat two cats in the yard");
StringBuffer sb = new StringBuffer();
while (m.find()) {
m.appendReplacement(sb, "dog");
}
m.appendTail(sb);
System.out.println(sb.toString());
}

Junit测试代码如下:

@Test
public void testReplaceChange(){
Regex r = new Regex();
r.replaceChange();
}


a)在方法r.replaceChange()使用断点,进行断点调试,先F5(Step into),在F6(Step over),运行结束输出:one cat two cats in the yard


b)Junit下使用Run As--Junit Test运行,输出结果为:one dog two dogs in the yard


问下出现这样的差异是为什么了?
1 楼 zhaoningbo 2012-04-11 兄台,我用junit4按你的代码测了一下,两种结果都是*dog*

读书人网 >编程

热点推荐