2008-11-26 32 views
7

也許這只是我,但我無法理解有關Intellij Idea中的Junit測試集成的文檔。我正在尋找的是一個簡單的教程示例,例如: 下面是一個計算2 + 2的方法,這裏是一個測試類,測試它爲4.這是您設置的複選框。如果網絡上已經存在這樣的事情,或者在Intellij Idea的幫助下,請將它引薦給我。 我使用Idea 7.0.4並希望使用JUnit 3.8或4. *。 TIA。需要在Intellij Idea中使用Junit的示例

回答

11

下面是如何使用的IntelliJ和JUnit

public class MathTest { // Press Ctrl-Shift-F10 here to run all tests in class 
    @Test 
    public void twoPlusTwo() { // Press Ctrl-Shift-F10 here to run only twoPlusTwo test 
     assertThat(2+2, is(4)); 
    } 

    @Test 
    public void twoPlusThree() { // Press Ctrl-Shift-F10 here to run only twoPlusThree test 
     assertThat(2+3, is(5)); 
    } 
} 

一旦運行測試一次小樣本,它會顯示在屏幕作爲運行「配置」的頂部。然後,您可以點擊綠色三角形重新運行測試,也可以使用調試三角形以調試模式運行並啓用斷點。