標籤:
今天是軟體測試的上機,主要內容是對junit的安裝以及對一個簡單類的測試實踐。老師推薦用eclipse,但是我原來一直在
用intellj Idea,所以我試了試intellj Idea對junit的安裝使用。下面介紹過程。
安裝:
intellj Idea 內建了junit模組,所以安裝起來很簡單。
首先,開啟intellj Idea,雙擊shift鍵,搜尋plugins,點擊中畫紅線的button。
進入plugins後,搜尋junit,選中下面畫紅圈外掛程式後面的對勾,然後確定並重啟intellj Idea。
至此安裝完成。
順帶一提,大量的快速鍵也是intellj Idea的魅力之一,讓人感覺非常方便,開發起來很舒服。
使用:
intellj idea 上junit的使用非常方便。首先在src平級目錄中建立測試檔案夾,這樣可以將測試代碼和被測試代碼分開。我這裡建立
的是test檔案夾,在該檔案夾上右鍵,點擊Mark Directory as --->Test Source Root
然後在src中建立要測試的類,選中類名,按ctrl+shift+T,點擊create new test
進入測試建立介面,如選擇箭頭所指的junit4確定就建立了測試類別
接下來就可以進行測試啦!
測試:
用來進行測試的代碼:
public class JunitTest { public String plus(double a,double b,double c){ if(a+b<=c||b+c<=a||a+c<=b)return"This is not a trangle"; else if(a==b&&a==c)return"This is an equilateral"; else if(a==b||a==c||b==c)return "This is an isosceles"; else return "This is a scalene"; }}
測試代碼:
import org.junit.Before;import org.junit.Test;import static org.junit.Assert.*;/** * Created by ltp on 2016/3/17. */public class JunitTestTest { private JunitTest junT; @Before public void setUp() throws Exception { junT = new JunitTest(); } @Test public void testPlus() throws Exception { assertEquals("This is not a trangle",junT.plus(22,3,4)); assertEquals("This is an equilateral",junT.plus(3,3,3)); assertEquals("This is an isosceles",junT.plus(3,3,4)); assertEquals("This is a scalene",junT.plus(5,3,4)); }}
點擊右上的edit configurations配置運行環境
然後就可以運行測試啦!
測試結果:
這就是junit在intellj idea中得安裝及使用方法。
軟體測試學習日誌———— round 2 Junit+intellj idea 安裝及簡單的測試使用