IDEA中快速使用单元测试——junit4举例

1. 新建一个测试类StringTest

public class StringTest {
    private int number;
    private String name;

    public StringTest() {
    }

2. 在类中编写测试方法test1

public class StringTest {
    private int number;
    private String name;

    public StringTest() {
    }

    public void test1() {
        System.out.println("hello, world!");
    }
}

3. 方法上,加 [@Test] 注解

public class StringTest {

    private int number;
    private String name;

    public StringTest() {
    }

    @Test
    public void test1() {
        System.out.println("hello, world!");
    }

}

4. 按 [Alt + Enter],导入 [junit4] 测试包

image

image

image

5. 导入成功,测试结果

导入成功后,[External Libraries] 中多了 [JUnit4]
image
点击 [test1] 方法,运行
image

posted @ 2022-03-05 12:57  hellozwx  阅读(308)  评论(0编辑  收藏  举报