用idea+maven+junit实现单元测试

注:此博客不再更新,所有最新文章将发表在个人独立博客limengting.site。分享技术,记录生活,欢迎大家关注

maven项目目录结构:注意测试文件要放在test目录下
用idea+maven+junit实现单元测试_第1张图片

pom.xml配置加上:


        
            junit
            junit
            4.12
            test
        

TestJunit.java:

package sunnietest;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

public class TestJunit {
    public static void main(String[] args) {
        System.out.println("aa");
    }

    @Test
    public void testJunit(){
        System.out.println("hello junit!");
    }

    @Before
    public void testBefore(){
        System.out.println("before!");
    }

    @After
    public void testAfter(){
        System.out.println("after!");
    }
}

输出结果:
用idea+maven+junit实现单元测试_第2张图片

你可能感兴趣的:(开发问题)