software testing lab1

1. Install Junit(4.12), Hamcrest(1.3) with Eclipse

First, download the junit.jar and hamcrest-core.jar from the website.

Then, open the eclipse. Choose properties--java build path-libraries. Click Add External JARs. Type in the path of junit.jarand hamcrest-core.jar. add the path.

2. Install Eclemma with Eclipse

Open Eclipse. Click help-> Eclipse Marketplace and search Eclemma. Install it.

 

 

3. Write a java program for the triangle problem and test the program with Junit.

The code:

Main.java

package triangle;

 

public class main {

    public int a,b,c;

    public String xing;

    public String san(int a,int b,int c){

        int temp;

        if(a>b){

           temp=a;

           a=b;

           b=temp;

        }

        if(b>c)

        {

           temp=b;

           b=c;

           c=temp;

        }

        if(a>b){

           temp=a;

           a=b;

           b=temp;

        }

        if(a+b<=c){

           xing="not a triangle ";

           return xing;

        }

        else{

           if(a == b&&b ==c){

               xing = "equilateral";

               return xing;

           }

           else if((a == b)||(b == c)){

               xing ="isosceles";

               return xing;

           }

           else

           {

               xing = "scalene";

               return xing;

           }

        }

    }

}

 

Maintest.java

package triangle;

 

import static org.junit.Assert.*;

 

import org.junit.After;

import org.junit.Before;

import org.junit.Test;

 

public class mainTest {

       main tra;

       String xing;

 

       @Before

       public void setUp() throws Exception {

              tra= new main();

       }

 

       @After

       public void tearDown() throws Exception {

       }

 

       @Test

       public void testequilateral(){

              xing = tra.san(1, 1, 1);

              assertEquals("equilateral",xing);

       }

      

       @Test

       public void testisosceles(){

              xing = tra.san(2, 3, 2);

              assertEquals("isosceles",xing);

       }

      

       @Test

       public void testscalene(){

              xing = tra.san(3, 5, 4);

              assertEquals("scalene",xing);

       }

       @Test

       public void testnot(){

              xing = tra.san(3, 2, 1);

              assertEquals("not a triangle ",xing);

       }

 

}

 

The result:

 

 

转载于:https://www.cnblogs.com/jyc-blog/p/6537726.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值