Software Testing, Lab 1

Posted zhaogang3015207537

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Software Testing, Lab 1相关的知识,希望对你有一定的参考价值。

Software Testing, Lab 1

一.实验要求:

  1. Install Junit(4.12), Hamcrest(1.3) with Eclipse
  2. Install Eclemma with Eclipse
  3. Write a java program for the triangle problem and test the program with Junit.

a)       Description of triangle problem:

Function triangle takes three integers a,b,c which are length of triangle sides; calculates whether the triangle is equilateral, isosceles, or scalene.

 

二.实验过程

1.JUnit、Hamcrest的安装:

从网上下载junit-4.12.jar 和 hamcrest-all-1.3.jar文件。

 

2.

1)在Eclipse中新建项目 (File - new - javaproject)

右键点击项目,选择Build Path - Configure Build Path

然后点击Libraries - Add External JARs,选择jar包打开,确认

 

2)Eclemma的安装:

在菜单栏选择Help - Eclipse Marketplace,搜索Eclemma,点击Install安装,重启Eclipse

 

 

 

3.代码编写

1)triangle.java

package hw;

 

public class triangle {

 

    public static void main(String[] args) {

       // TODO Auto-generated method stub

 

    }

   

    public int tri(int a,int b,int c){

       int m=0;

       if(a+b>c&&a+c>b&&b+c>a){

           if(a==b&&b==c) m=1;  //equilateral

           else if(a==b||b==c||a==c) m=2;  //isosceles

           else m=3;  //scalene

       }

       else m=-1;

      

       return m;

    }

 

}

 

2)triangleTest.java

package hw;

 

import static org.junit.Assert.*;

 

import org.junit.Test;

 

public class triangleTest {

   

    triangle t = new triangle();

   

    @Test

    public void test() {

       int f = t.tri(1,1,1);

       assertEquals( 1 , f );

       f = t.tri(2,2,3);

       assertEquals( 2 , f );

       f = t.tri(2,3,4);

       assertEquals( 3 , f );

       f = t.tri(1,1,4);

       assertEquals( -1 , f );

    }

 

}

 

 

三.实验结果

各种情况的测试用例各一个,测试结果均通过

 

equilateral triangle返回1, isosceles triangle返回2,scalene triangle返回3,不能构成三角形则返回-1

 

测试结果如图

技术分享图片

 

以上是关于Software Testing, Lab 1的主要内容,如果未能解决你的问题,请参考以下文章

SOFTWARE TESTING LAB 01

Software Testing Lab1

Software Testing_Lab 2_selenium

Software Testing Lab 1

Software Testing lab01

Software Testing Techniques LAB 02: Selenium