* 格式化后的數據為小寫字母,并且使用下劃線分割命名單詞
*
* 例如:employeeInfo 經過格式化之后變為 employee_info
*
* @param name Java對象名稱
*/
public static String wordFormat4DB(String name){
Pattern p = Pattern.compile("[A-Z]");
Matcher m = p.matcher(name);
StringBuffer sb = new StringBuffer();
while(m.find()){
m.appendReplacement(sb, "_"+m.group());
}
return m.appendTail(sb).toString().toLowerCase();
}
}
它是否能按照預期的效果執行呢?嘗試為它編寫 JUnit 單元測試代碼如下:
package com.ai92.cooljunit;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
public class TestWordDealUtil {
//測試wordFormat4DB正常運行的情況
@Test public void wordFormat4DBNormal(){
String target = "employeeInfo";
文章來源于領測軟件測試網 http://www.kjueaiud.com/