2. Application of Logic overlay
• Write Java code (implemented using classes and methods) in accordance with the program flowchart given
Write a test case that is overwritten by a statement, a branch overlay, and the path it covers, and test with JUnit to write test cases
Package HAN;
import Java.util.Scanner;
/**
*
* @author Hanzhenyi
* 2016.4.7
* 2, the application of logic coverage
*/
Public class a {
Public Static void Main (string[] args) {
Scanner in = new Scanner (System. in);
System. out. println ("Please enter the first number x:");
int x = In.nextint ();
System. out. println ("Please enter a second number 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 the output X is:" +x+ ", the value of the output Y is:" +y+ ");
}
Public void Demo (int i, int j) {
TODO auto-generated Method stub
}
}
Statement overrides:
Path |
Test Case X |
Test Case Y |
Aeg |
3 |
0 |
Aef |
6 |
0 |
Abc |
5 |
3 |
Branch Overrides
Path |
Test Case X |
Test Case Y |
Aeg |
3 |
0 |
Aef |
6 |
0 |
Abc |
5 |
3 |
Abd |
5 |
1 |
Package HAN;
Import static org.junit.assert.*;
Import Org.junit.Before;
Import Org.junit.Test;
public class Twotest {
@Before
public void SetUp () throws Exception {
}
@Test
public void Test () {
Both demo =new ();
Demo.demo (3,0);
Demo.demo (6,0);
Demo.demo (5,3);
Demo.demo (5,1);
}
Software Test Third Job 2