您的位置:軟件測試 > 開源軟件測試 > 開源單元測試工具 > junit
junit使用簡明手冊
作者:網(wǎng)絡(luò)轉(zhuǎn)載 發(fā)布時間:[ 2014/2/18 14:18:29 ] 推薦標簽:junit 單元測試工具

junit是java中書寫unit test的framework,目前一些流行的unit test工具大都都是在junit上擴展而來的。本文針對的的版本是junit3.8.1,可以從www.junit.org上下載。新版本是junit4.1,一般新的myeclipse開發(fā)環(huán)境中都集成了的。

安裝

    First, download the latest version of JUnit, referred to below as junit.zip.

    Then install JUnit on your platform. of choice:

    Windows

    To install JUnit on Windows, follow these steps:

        Unzip the junit.zip distribution file to a directory referred to as %JUNIT_HOME%.

        Add JUnit to the classpath:

        set CLASSPATH=%CLASSPATH%;%JUNIT_HOME%junit.jar

    Unix (bash)

    To install JUnit on Unix, follow these steps:

        Unzip the junit.zip distribution file to a directory referred to as $JUNIT_HOME.

        Add JUnit to the classpath:

        export CLASSPATH=$CLASSPATH:$JUNIT_HOME/junit.jar

    (Optional) Unzip the $JUNIT_HOME/src.jar file.

    Test the installation by using either the textual or graphical test runner to run the sample tests distributed with JUnit.

    Note: The sample tests are not contained in the junit.jar, but in the installation directory directly. Therefore, make sure that the JUnit installation directory is in the CLASSPATH.

    For the textual TestRunner, type:

        java junit.textui.TestRunner junit.samples.AllTests

    For the graphical TestRunner, type:

        java junit.swingui.TestRunner junit.samples.AllTests

    All the tests should pass with an "OK" (textual) or a green bar (graphical).

    If the tests don't pass, verify that junit.jar is in the CLASSPATH.

    Finally, read the documentation.

用法

1.       基本使用步驟,Junit的使用非常簡單,它的基本使用步驟:

-          創(chuàng)建,從junit.framework.TestCase派生unit test需要的test case

-          書寫測試方法,提供類似于如下函數(shù)簽名的測試方法:

public void testXXXXX();

-          編譯,書寫完test case后,編譯所寫的test case類

-          運行,啟動junit test runner,來運行這個test case。

Junit提供了2個基本的test runner:字符界面和圖形界面。啟動命令分別如下:

a 圖形界面:

java junit.swingui.TestRunner XXXXX

b 字符界面:

java junit.textui.TestRunner XXXXX

上一頁123下一頁
軟件測試工具 | 聯(lián)系我們 | 投訴建議 | 誠聘英才 | 申請使用列表 | 網(wǎng)站地圖
滬ICP備07036474 2003-2017 版權(quán)所有 上海澤眾軟件科技有限公司 Shanghai ZeZhong Software Co.,Ltd