手机版

邓松软件测试实验指导书(20140907采用)(20)

时间:2025-07-09   来源:未知    
字号:

}

String result = WordDealUtil.wordFormat4DB(target);

assertEquals("employee_info", result);

//测试当尾字母为大写时的情况

@Test public void wordFormat4DBEnd(){ }

//测试多个相连字母大写时的情况

@Test public void wordFormat4DBTogether(){ }

String target = "employeeAInfo";

String result = WordDealUtil.wordFormat4DB(target);

assertEquals("employee_a_info", result); String target = "employeeInfoA";

String result = WordDealUtil.wordFormat4DB(target);

assertEquals("employee_info_a", result);

4)查看分析运行结果,修改错误代码

再次运行测试。JUnit 运行界面提示我们有两个测试情况未通过测试(见图6),当首字母大写时得到的处理结果与预期的有偏差,造成测试失败(failure);而当测试对 null 的处理结果时,则直接抛出了异常——测试错误(error)。显然,被测试代码中并没有对首字母大写和 null 这两种特殊情况进行处理,修改如下:

//修改后的方法wordFormat4DB public static String wordFormat4DB(String name){ if(name == null){ return null; } Pattern p = pile("[A-Z]"); Matcher m = p.matcher(name); StringBuffer sb = new StringBuffer(); while(m.find()){ if(m.start() != 0) m.appendReplacement(sb, ("_"+m.group()).toLowerCase());

邓松软件测试实验指导书(20140907采用)(20).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
×
二维码
× 游客快捷下载通道(下载后可以自由复制和排版)
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能出现无法下载或内容有问题,请联系客服协助您处理。
× 常见问题(客服时间:周一到周五 9:30-18:00)