"Software Testing" experiment three

Source: Internet
Author: User
Tags greatest common divisor

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

Related Article

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.