Junit4 with Intellij Idea and Maven

1. 預準備工作

  • Intellij Idea
  • maven3.x

2. 在maven中配置junit倉庫

在對應module的pom.xml中,添加:

<dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
        </dependency>
    </dependencies>

3. 在Maven特定目錄下生成junit test文件

例如:我要在maven中的src/test/java中的com.okingniko.test包中生成com.okingniko.designpattern.state.GumballMachine的單元測試文件

1. 在需要生成測試的文件中,右鍵=>go to=>test (或者使用快捷鍵ctrl+shift+T)

2. 選中create new test,進行測試名、測試目標package、測試方法(plus junit @before, @after)等的配置

3. Enjoy it!

ps: 你也可以下載Junit Generator2 插件,而後使用Alt+Insert快捷鍵進行junit test文件的自動生成

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