首页 > 其他 > 详细

Junit单元测试

时间:2016-08-09 14:50:31      阅读:181      评论:0      收藏:0      [点我收藏+]
package com.ss1.junit;

public class Calculator {

    public int add(int one, int another) {
        // 为了简单起见,暂不考虑溢出等情况。
        return one + another;
    }

    public int multiply(int one, int another) {
        // 为了简单起见,暂不考虑溢出等情况。
        return one * another;
    }
    
}
package com.ss1.junit;

import static org.junit.Assert.*;

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

public class CalculatorTest {
    
    private Calculator calculator;

    @Before
    public void setUp() throws Exception {
        calculator = new Calculator();
    }

/*    @Test
    public void test() {
        fail("Not yet implemented");
    }
*/
    @Test
    public void testAdd() throws Exception{
        int sum = calculator.add(1,2);
         assertEquals(3, sum);
    }
    
    @Test
    public void testMultipy() throws Exception{
        int product = calculator.multiply(2,4);
         assertEquals(9, product);
    }
    @Test
    @Ignore("not implemented yet")//该方法未完成,跳过对此方法的验证
    public void testIgnore() throws Exception{
        
    }
}

 

Junit单元测试

原文:http://www.cnblogs.com/tingbogiu/p/5753164.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!