java的junit的测试

public class Caculator {
    public int add(int a, int b) {
        return a + b;
    }
}

测试类


import mystring.junit.Object.Caculator;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

public class CaculatorTest {

    //初始化操作,自动进行,用来放公共初始化操作
    @Before
    public void init(){
        System.out.println("初始化...");
    }

    @Test
    public void Testadd(){
        System.out.println("测试...");
        Caculator caculator = new Caculator();
        int result = caculator.add(1, 3);
        //断言(期望值,计算值)
        Assert.assertEquals(4,result);
    }

    //结束时自动结束
    @After
    public void close(){
        System.out.println("结束...");
    }
}


posted @ 2021-05-04 10:34  code-G  阅读(69)  评论(0编辑  收藏  举报