Junit单元测试类的使用

版权声明:此文为本人所写,严禁版权侵占行为。如需转载请注明出处。 https://blog.csdn.net/Abby_lxf/article/details/88920720

Junit单元测试类
1.当前工程下-》右键build path -》add libraries ->Junit4(里面包括测试时可用的jar包)
2.在主类中,创建一个空参的无返回值的方法,如:用于代码的测试,方法上的声明:@Test
3.导入inport org.junit.Test;
4.在test1()方法中进行代码的编写
5.当运行时,双击选中要运行的方法名,右键Run as->JUnit Test运行测试类

import org.junit.Test;

public class Wrapper {
    public static void main(String[] args) {
        String str = "AAA";
        System.out.println(str);
    }
    @Test
    public void test2() {
        m1();
    }
    
    @Test
    public void test1() {
        String str = "AAA";
        System.out.println(str);
        m1();
    }
    public void m1() {
        System.out.println("hello world!");
    }

}

猜你喜欢

转载自blog.csdn.net/Abby_lxf/article/details/88920720