Software Testing Techniques LAB 01: test Junit and Eclemma

1. Installing

     1. Install Junit and hamcrest

       First, I download the Junit-4.12.jar and hamcrest-core-1.3.jar

       

       Then. I add them into eclipse library

      

       

 

 

 

           

    After installing,

      

   2. Installing eclemma

 

       Installing with Eclipse Marketplace

       

 

 

2. Testing

  1. Coding

   Write a java program for the triangle problem, which can calculate whether the triangle is equilateral, isosceles or scalene.

   

package newTest;

public class Triangle {
	
	public int a;
	public int b;
	public int c;
	
	public Triangle(){
		
	}
	
	public Triangle(int a, int b, int c){
		this.a=a;
		this.b=b;
		this.c=c;
	}
	
	public String calculate(){
				
		if ( a + b <= c || b + c <= a || c + a <= b ){
			return "Not a triangle";
		}
		else if( a == b && a == c ){
			return "equilateral";
		}
		else if( a == b || a == c || b == c ){
			return "isosceles";
		}
		else{
			return "scalene";
		}
	}
	

}

2. Creating Junit test case

 

 

 

 

 

 

Then, finish the test case

 

package newTest;

import static org.junit.Assert.*;

import org.junit.Before;
import org.junit.Test;

public class TriangleTest {
	
	public Triangle tri;

	@Before
	public void setUp() throws Exception {
	}

	@Test
	public void testCalculate() {
		tri = new Triangle(1,1,1);
		assertEquals("equilateral",tri.calculate());
		tri = new Triangle(2,2,3);
		assertEquals("isosceles",tri.calculate());
		tri = new Triangle(2,2,1);
		assertEquals("isosceles",tri.calculate());
		tri = new Triangle(3,4,5);
		assertEquals("scalene",tri.calculate());
		tri = new Triangle(3,5,9);
		assertEquals("Not a triangle",tri.calculate());
	}

}

 

3. Testing and debug

 

    Run the Junit test case, I found some Failures, then I correct them.

 

 

    The last is Coverage Testing with Eclemma

 

 

posted @ 2017-03-10 13:38  杨震宇  阅读(211)  评论(0)    收藏  举报