最近,我在编写一款自娱自乐的单词对比记忆的软件NITIAN WORD,这里选取它的一部分逻辑,利用白盒方法进行测试,算是理论联系实际吧。
主要逻辑代码:
String wordsArray[] = new String[Global.input_words_ceiling]; NTDictionary dict = new NTDictionary(); while(!endFlag) { System.out.println("----------------------------------------------------------"); System.out.println("please input a group of English words"); System.out.println("words separated by a space, and end up with the key Enter"); System.out.println("and enter q to quit"); sc = new Scanner(System.in); String st = sc.nextLine().trim(); // wipe out the head and the tall space if(st.equals("q")) { endFlag = true; System.out.println("you have exit normally"); } else if(st.equals("")) { System.out.println("the input should not be empty"); } else { //use regular expression to make sure that the string only consists of English characters Pattern pattern = Pattern.compile("^[A-Za-z\\s]+$"); Matcher matcher = pattern.matcher(st); boolean isAllEngFlag = matcher.matches(); if(isAllEngFlag == true) { wordsArray = st.split("\\s+"); // wipe out more spaces and get each word int isExist = dict.judgeExistence(wordsArray); //judge whether there is the identical entry if(isExist == 0) { dict.collectWords(wordsArray);//if not exist, collect the entry System.out.println("yeah, SUCCESS"); } else { System.out.println("there is already entry"); System.out.println("the line num is-----> " + isExist); } } else { System.out.println("your input shoud only be composed of English characters"); } }
白盒测试之语句覆盖:
白盒测试之判定覆盖:
测试情况:
总结:
这里语句覆盖和判定覆盖所用的最少测试用例一模一样,这是因为只要执行到一个可执行语句,就意味着结束,所以有多少个执行语句,就有多少个测试用例,从而达到语句覆盖的目的。而在判定覆盖中,只要用例能全部执行到可执行代码实际上就涵盖了所有的分支,同样一个用例只能执行一个可执行语句。所以二者的用例一模一样,证明完毕。
白盒测试实战——NITIAN Word,布布扣,bubuko.com
原文:http://blog.csdn.net/bluecloudmatrix/article/details/23497447