使用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
问下为什么会出现这样的情况了?