JUNIT测试工具

Junit是单元测试框架工具

1.定义一个测试的程序类

package test3;

public class Math {
    
    private Math() {}
    public static int add(int x , int y) {
        // TODO Auto-generated method stub
        //private Math() {}
        int result = 0;
        result = x + y;
        return result;
        
    }

}

2.定义一个junit的测试类

package test3;

import static org.junit.Assert.*;

import org.junit.Test;

import junit.framework.TestCase;

public class MathTest {

    @Test
    public void test() {
        //fail("Not yet implemented");
        TestCase.assertEquals(test3.Math.add(11, 22), 33);
    }

}

正确样例为这个:

失败为这个:

Last modification:February 4th, 2020 at 04:35 pm
如果觉得我的文章对你有用,请随意赞赏