Experiment Three white Box test
Experimental purpose
(1) Learn white box test method
(2) Mastering the logic covering methods of statement coverage, conditional coverage, branch coverage, etc.
(3) Mastering the use of Java Code Analysis tools
Experimental content
1. computes the greatest common divisor of an integer x and an integer y. (not allowed in the way the classroom is used)
L Use classes and methods (define a class, define a greatest common divisor method in the Class), and name it according to the specification.
L GET the two integers entered by the user in the main method, call the previously written method, and output their greatest common divisor.
L use FindBugs to find out if there are any bugs in the program.
Package Lin;
Import Java.io.BufferedReader;
Import java.io.IOException;
Import Java.io.InputStreamReader;
Lin Jiaqi 3137102103
First question
public class First {
public static void Main (string[] args) {
int a = 0;
System.out.print ("Please enter the first number:");
BufferedReader strin=new BufferedReader (New InputStreamReader (system.in));
try {
A=integer.parseint (Strin.readline ());
} catch (NumberFormatException e) {
E.printstacktrace ();
} catch (IOException e) {
E.printstacktrace ();
}
int b = 0;
System.out.print ("Please enter a second number:");
BufferedReader strin2=new BufferedReader (New InputStreamReader (system.in));
try {
B=integer.parseint (Strin2.readline ());
} catch (NumberFormatException e) {
E.printstacktrace ();
} catch (IOException e) {
E.printstacktrace ();
}
int flag = 0;
for (int i = 1; i <= A; i++) {
if (a%i==0) {
if (b%i==0) {
Flag=i;
}
}
}
System.out.println ("Greatest common divisor as:" +flag);
}
}
2. Application of Logic overlay
L write out the test cases covered by the statement, the branch coverage, and the path it covers, according to the program flowchart given.
Package Jia;
Import Java.util.Scanner;
public class Second {
Lin Jiaqi 3137102103
Second question
public static void Main (string[] args) {
TODO auto-generated Method Stub
Scanner in = new Scanner (system.in);
System.out.println ("Please enter the value of x:");
int x = In.nextint ();
System.out.println ("Please enter the value of y:");
int y = In.nextint ();
if (x<4 | | y>0) {
if (y>1) {
y=y+1;
}
}else{
if (x>=5) {
X=x-y;
}
else{
X=x+y;
}
}
System.out.println (the value of "X" is: "+x+", the value of Y is: "+y+". ");
}
public void II (int i, int j) {
TODO auto-generated Method Stub
}
public void second (int i, int j) {
TODO auto-generated Method Stub
}
}
Package Jia;
Import static org.junit.assert.*;
Import Jia. Second;
Import Org.junit.Before;
Import Org.junit.Test;
public class Secondtest {
@Before
public void SetUp () throws Exception {
}
@Test
public void Test () {
Second Second =new Second ();
Second.second (5,7);
Second.second (2,0);
Second.second (7,-1);
}
}
"Software Testing" experiment three