java Junit 单元测试

1、注意

@Test注解,方法不能有返回值,不能有参数,不能修饰static

2、使用

a、单独建一个类用来做测试

b、案例

功能类

package com.wt.unit;

public class CountValue {

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

    public int sub(int a, int b){
        return a - b;
    }

}

测试类

package com.wt.unit;

import org.junit.Test;

public class Demon01 {
    // 用于进行单元测试的类
    @Test
    public void add(){
        int add = new CountValue().add(10, 5);
        System.out.println("add = " + add);
    }

    @Test
    public void sub(){
        int sub = new CountValue().sub(23, 16);
        System.out.println("sub = " + sub);
    }
}

 

posted @ 2025-04-21 19:26  市丸银  阅读(8)  评论(0)    收藏  举报