zoukankan      html  css  js  c++  java
  • 3137102432_ 施少兵_ lab3

    《软件测试》实验

    实验三 白盒测试                                                      

    实验目的

    (1)       学习白盒测试方法

    (2)       掌握语句覆盖、条件覆盖、分支覆盖等逻辑覆盖方法

    (3)       掌握Java代码分析工具的使用

    实验内容

    1、 计算整数X和整数Y的最大公约数。(不允许采用课堂上所用的方式实现)

    l         请用类和方法实现(定义一个类,在类中定义一个求最大公约数的方法),命名时请按照规范命名。

    l         在main方法中获取用户输入的两个整数,调用之前写的方法,输出它们的最大公约数。

    l         利用FindBugs查找程序中是否存在bug。

    import java.util.Scanner;

    public class test1{

        public static void main(String[] args) {

            Scanner sc= new Scanner(System.in);

             int num1;

             int num2;

             System.out.print("请输入一个数:");

             num1= sc.nextInt();

             System.out.print("请输入另一个数:");

             num2= sc.nextInt();

            

             System.out.println("最大公约数为:"+gongyue(num1, num2));

            

            }

             public static int gongyue(int num1, int num2) {

             while(num1%num2!=0){

                 int num=num1%num2;

                 num2=num1;

                 num1=num;

              }

             return num1;

            }

    }

    import junit.framework.TestCase;

    import java.util.Scanner;

    public class test1Test extends TestCase {

    public static void main(String[] args) {

    // TODO Auto-generated method stub

    Scanner scanner = new Scanner(System.in);

    System.out.println("请输入第一个整数X:");

    int x = scanner.nextInt();

    System.out.println("请输入第二个整数Y:");

    int y = scanner.nextInt();

    test1 cal = new test1();

    System.out.println("整数X和整数Y的最大公约数为:"+test1.gongyue(x, y));

    }

    }

    2逻辑覆盖的应用

    l         按照所给的程序流程图,分别写出语句覆盖、分支覆盖的测试用例,以及它所覆盖的路径

    l         附加题:根据程序流程图,写出代码(定义一个类和方法来实现),用JUnit生成单元测试,并利用前面设计的测试用例进行测试。

    public class test2 {

        public void test2(int x,int y){

            int k=0,j=0;

            if((x<4 || y>0)&&(y>1)){

                y=y+1;

            }

           else {

           if(x>=5){

                x=x-y;

           }

                else{

                    x=x+y;

                    }

                 }

          if((x<4 || y>0)&&(y<1 || y==1)){

     

          }

          System.out.println("x的值为:"+x);

          System.out.println("y的值为:"+y);

        }

    }

    语句覆盖:

    X =5         y =0                路径aeg

    X=3          y=2                路径abc

    分支覆盖:

    X=5/4            y=1             路径aef/aeg

    X=3              y=1/3           路径abd/abc

    import junit.framework.TestCase;

    public class test2Test extends TestCase {

            public void testDoWork(){

            System.out.println("对设计的x=1,y=2这组测试用例进行单元测试:");

            test2 work = new test2();

            work.test2(1, 2);

            System.out.println("对设计的x=3,y=-1这组测试用例进行单元测试:");

            work.test2(3, -1);

            }  

    }

  • 相关阅读:
    POJ Problem 1363 Rails 【栈】
    POJ Problem 3040 Allowance 【贪心】
    ACM 程序对拍
    HDU Problem
    POJ
    HDU Problem
    HDU Problem—2124 Repair the Wall 【贪心】
    HDU Problem 1052 Tian Ji -- The Horse Racing 【贪心】
    POJ Problem Radar Installation 【贪心】
    Beyond Compare和输出文件比较的方法
  • 原文地址:https://www.cnblogs.com/shishaobing/p/5396109.html
Copyright © 2011-2022 走看看