Experiment Four white Box test

Source: Internet
Author: User

Experimental purpose

(1) Skills to master static analysis code

(2) Equivalence class division in the study of black box testing

Experimental content

First, find out the problems in the function. The following topics are completed in the LAB04 project.

1, a site through the user input user name and password (entered in the login.jsp login page) to determine what kind of interface, if the administrator (that is, the user named Admin or administrator) jump to the Administrator page (welcome_admin.jsp), Non-administrative users jump to the normal user interface (welcome.jsp). Visitors visit the site, no need to enter the user name and password, directly into the normal user interface (welcome.jsp)

Requirements: Identify the problem with the Getuserrole () method in the Useroperation.java file, explain the cause of the problem , and modify it .

Description: Not required to write JUnit unit test cases, you can imagine the test data, through static analysis, with dynamic debugging to find the problem.

The problem with the Getuserrole () method is that it does not define ordinary users and visitors

Reason: Did not determine whether the user name is a null value, ignoring the visitor user, because if not empty, then tourists, non-empty, to continue to determine whether it is an administrator or a normal user

Modify:

Public class useroperation {

/**

* According to the user name to determine whether it is empty, if it is empty, then tourists, if not empty, then judge is the administrator or ordinary visitors

* @return User Role

*/

Public String Getuserrole (String userName) {

String userrole= "Guest";

if (username!=null) {

if (Username.equals ("admin") | | username.equals ("Administrator")) {

userrole= "admin";

}

}Else{

Userrole= "Guest";

}

return userrole;

}

2, user registration (register.jsp) to enter the age field, the user input parameters from the Useroperation.java file Validateuserage () method, converted to a numeric type, to determine whether the age between 18~26 (including 18 and 26), If the age is within this interval, then return true to jump to the login.jsp page, otherwise pop-up prompts that indicate "user age input is incorrect".

Requirements: Identify the problem with the Validateuserage () method in the Useroperation.java file, explain the cause of the problem , and modify it .

Problem: Input string, display empty, enter special symbol, exception occurs

Modify:

/**

* Converts the age entered by user registration to a numeric type,

* @return verified by returning true, otherwise false is returned

* @throws exception run out of exception

*/

Public boolean validateuserage (String userage) throws exception{

if (Integer. parseint (userage) <18 | | Integer. parseint (userage) >26) {

return true;

}

Else { throw new Exception ("Input is incorrect, please re-enter");

}

}

}

Second, the use of the equivalent class division in the black box test to complete the following topics

3, a procedure stipulates: "Input three non 0 positive integers a, B, c as the three sides of the side length of the triangle (the case of special triangles are not considered). According to the instructions given, divide by equivalence class partitioning, and give each equivalence class A unique number.

Valid equivalence classes

Number

Invalid equivalence class

Label

A+b>c

1

A+b<c

A+b=c

9

10

B+c>a

2

B+c<a

B+c=a

11

12

A+c>b

3

A+c<b

A+c=b

13

14

A-b<c

4

A-b>c

A-b=c

15

16

A-c<b

5

A-c>b

A-c=b

17

18

B-c<a

6

B-c>a

B-c=a

19

20

Positive integers

7

A,b,c at least one is a negative integer

A,b,c at least one is a decimal

21st

22

Not 0

8

A,b,c at least one for 0

23

Experiment Four white Box test

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.