軟體測試學習日誌———— round 2 Junit+intellj idea 安裝及簡單的測試使用

來源:互聯網
上載者:User

標籤:

  今天是軟體測試的上機,主要內容是對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 安裝及簡單的測試使用

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.