您的位置:軟件測(cè)試 > 開源軟件測(cè)試 > 開源單元測(cè)試工具 > junit
JUNIT測(cè)試通過的HelloWorld
作者:網(wǎng)絡(luò)轉(zhuǎn)載 發(fā)布時(shí)間:[ 2013/1/15 14:46:26 ] 推薦標(biāo)簽:

把我剛測(cè)試成功的例子(3分鐘前)記錄下來放在這里,希望會(huì)對(duì)剛開始研究Junit的朋友有點(diǎn)幫助。

到j(luò)akarta當(dāng)一份apache-ant安裝到你的系統(tǒng)上,并把a(bǔ)nt/bin加到系統(tǒng)變量path中,使你的ant命令可以在任何地方被調(diào)用。
當(dāng)一份junit3.8.1安裝到你的系統(tǒng)上(解壓縮,把junit.jar加到系統(tǒng)變量classpath中)。

建立測(cè)試目錄JunitTest
把java文件,統(tǒng)一放到JunitTest/src目錄,根據(jù)package建與之相關(guān)的目錄.
文件1:

HelloWorld.java

package com.company;

public class HelloWorld {
public String sayHello() {
return "Hello World!";
}

public static void main( String[] args ) {
HelloWorld world = new HelloWorld();
System.out.println(world.sayHello());
}
}

 

文件2:

AllJunitTests.java

package test.com.company;

import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;

public class AllJunitTests extends TestCase{
public AllJunitTests(String name){
super(name);
}

public static Test suite(){
TestSuite suite = new TestSuite();
//TestSuite suite = new TestSuite();
suite.addTestSuite(HelloWorldTest.class);

return suite;
}
}


文件3:


HelloWorldTest.java

package test.com.company;

import com.company.HelloWorld;
import junit.framework.TestCase;
import junit.framework.AssertionFailedError;
import junit.framework.Assert;


/**
* JUnit 3.8.1 testcases for HelloWorld
*/
public class HelloWorldTest extends TestCase {

public HelloWorldTest(String name) {
super(name);
}

public static void main(String args[]) {
junit.textui.TestRunner.run(HelloWorldTest.class);
}

public void testSayHello() {
HelloWorld world = new com.company.HelloWorld();
assertEquals("Hello World!", world.sayHello() );
}
}

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