The third blog assignment of software testing course

Source: Internet
Author: User

1, a website management system, the user registration, the phone number is optional input, the input format is: Area code-Telephone number-extension number, in the middle with "-" separated. The following is the design on the JSP page and does not have any control over the input.

Suppose the system now needs to take out the middle phone number part, the code is as follows:

/**

*

* This method takes the middle phone number part according to user input.

* @param strphonenum phone number, such as: "0591-83279988-002"

* @return return number section, e.g. "83279988"

*/

public string Getphonenumber (string strphonenum) {

if ((strphonenum==null) | | | "". Equals (Strphonenum)) {

Return "";

}

String[] Arrphone=strphonenum.split ("-");

return arrphone[1];

}

Use the techniques and methods you have learned to identify the problems in this approach, and analyze the cause of the problem, and give your solution. (Hint: there is more than one problem)

Requirements:

(1) Write the question

① Enter the correct 0591-83279988-002 format and cannot output phone number

② input containing letter spaces and other error messages can still be output

(2) Write down the reason why the problem arises

①jsp phone number in the format of "area code-Phone number-extension number", only split ("-") can not distinguish between phone number and extension number

② does not add a judgment on whether the input is a number

(3) Give the modified code

public string Getphonenumber (string strphonenum) {
if ((strphonenum==null) | | | "". Equals (Strphonenum)) {
Return "Input cannot be empty";
}
String[] Arrphone=strphonenum.split ("[-——]");
if (!arrphone[1].matches ("[0-9]+")) {
Return "input must be a number";
}else{
return arrphone[1];
}
}

2, write a paragraph for the integer array sorting code, explain your design ideas, and use the error-guessing method to give a possible error (at least 5), design the test case, and use JUnit to write unit tests to test. (assuming that the passed-in parameter has been determined to be an integer array)

Requirements:

(1) Write code, and conform to code specification (naming to specification, not directly written in the main method, need to have class comments, method comments, and appropriate line comments)

public class Test2 {
/*
* @author: Xie Liming
*2016-04-26
* Ascending order of the integers entered
*/
@Test
public void Test () {//implementation method
System.out.println ("Please enter integers to be sorted and separate them with commas:");
Scanner sc=new Scanner (system.in);
String Inputstring=sc.next (). toString (). Trim ();
String array[]=inputstring.split (",");
int num[]=new Int[array.length];
for (int i=0;i<array.length;i++) {
Num[i]=integer.parseint (Array[i]);
}
Arrays.sort (num); Sort the num array in ascending order using the Sort method of the arrays class
for (int j=0;j<array.length;j++) {
System.out.print (num[j]+ "");
}
}
}

(2) Explain your design ideas

The sort () method of the arrays class makes it easy to sort the contents of the array in ascending order, this method can satisfy the requirement of the problem, so we just need to get the integer string of the user input, then separate it into the array, and use the Sort method to complete the

its sort.

(3) Write a possible error (at least five kinds)

① the integer entered contains a negative test case: 11,1,10,-1,25

The integer entered by the ② contains 0 test cases: 20,0,1,21,100

③ the integer entered has two or more than two identical test cases: 50,99,2,2,4

④ input integers have already been sorted. Test Cases: 1,2,3,4,5

⑤ input integers all the same test cases: 1,1,1,1,1

(4) Write JUnit unit tests to put the test data that was previously given in the possible error into the unit test for testing

The third blog assignment of software testing course

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.