白盒测试实战——NITIAN Word

来源:互联网 发布:揭秘网络棋牌骗局 编辑:程序博客网 时间:2024/05/22 00:52

最近,我在编写一款自娱自乐的单词对比记忆的软件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 spaceif(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 charactersPattern 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 wordint isExist = dict.judgeExistence(wordsArray); //judge whether there is the identical entryif(isExist == 0) {dict.collectWords(wordsArray);//if not exist, collect the entrySystem.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");}}

程序流程图:



白盒测试之语句覆盖:


白盒测试之判定覆盖:


测试情况:


总结:

这里语句覆盖和判定覆盖所用的最少测试用例一模一样,这是因为只要执行到一个可执行语句,就意味着结束,所以有多少个执行语句,就有多少个测试用例,从而达到语句覆盖的目的。而在判定覆盖中,只要用例能全部执行到可执行代码实际上就涵盖了所有的分支,同样一个用例只能执行一个可执行语句。所以二者的用例一模一样,证明完毕。



2 0
原创粉丝点击