代码改变世界

个人项目

2015-04-27 10:56  lucky梦的继续  阅读(185)  评论(4编辑  收藏  举报

https://github.com/tengjuan/Individual-Project/blob/master/CalculatorTest

Github个人主页https://github.com/tengjuan

编写一个Calculator类,这是一个能够简单实现加减乘除、平方、开方的计算器类,然后对这些功能进行单元测试。

 

package andycpp;
import static org.junit.Assert.*;
import org.junit.Before;
 import org.junit.Ignore;
import org.junit.Test;
public class CalculatorTest {
    private static Calculator calculator = new Calculator();
    @Before
    public void setUp() throws Exception {   
     calculator.clear();  
  }
    @Test
    public void testAdd() {
        calculator.add(2);
        calculator.add(3);
        assertEquals(5, calculator.getResult()); 
   }  
    @Test
    public void testSubstract()
  {       
       calculator.add(10);   
       calculator.substract(2);
        assertEquals(8, calculator.getResult()); 
   }
    @Ignore(" Multiply() Not yet implemented")
 @Test
    public void testMultiply() {  
  }
    @Test
    public void testDivide() {      
       calculator.add(8);      
       calculator.divide(2);
        assertEquals(4, calculator.getResult());   
 }
 }

 总结:通过这个实验,了解一些软件测试的基本含义,学会了一些基本测试的步骤的设计和用例的构造。初步学会了junit4的使用,了解到基本流程和实现。