IDEA使用Junit單元測試

  1. 引入hamcrest-core-1.3.jar & junit-4.12.jar
    在這裏插入圖片描述

  2. 新建一個test路徑
    在這裏插入圖片描述

  3. 標記成test sources root
    在這裏插入圖片描述

  4. 到要測試的類方法,ctrl + shift + t,選擇create new test
    在這裏插入圖片描述

  5. 選擇Junit4 和要測試的方法
    在這裏插入圖片描述

  6. 左鍵點擊,run
    在這裏插入圖片描述
    ps:Junit不能是static,java.lang.Exception: Method main() should not be static
    不能有變量,java.lang.Exception: Method main should have no parameters
    測試方法必須是public void
    在這裏插入圖片描述

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