用idea+maven+junit實現單元測試

注:此博客不再更新,所有最新文章將發表在個人獨立博客limengting.site。分享技術,記錄生活,歡迎大家關注

maven項目目錄結構:注意測試文件要放在test目錄下
這裏寫圖片描述

pom.xml配置加上:

<!-- https://mvnrepository.com/artifact/junit/junit -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>

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!");
    }
}

輸出結果:
這裏寫圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章