接著
package junitsamples; import junit
samples MyBean;
import junitframework *; public class TestMyBean extends TestCase { //TestCase的子類
private MyBean aName; //構造被測類的對象
public TestMyBean(String name) {
super(name);
}
protected void setUp() { //進行初始化的任務
aName= new MyBean();
}public static Test suite() { //進行測試
return new TestSuite(TestMyBeanclass);
}public void testCon() { //對預期的值和con方法比較
AssertassertTrue(!aName equals(null)); //斷言
AssertassertEquals( Connection Success! aName con());
}
public void testGogo() { //對預期的值和gogo方法比較
aNamecon();
AssertassertTrue(!aName equals(null)); //斷言
AssertassertEquals( aName gogo( ));
}
}
解釋如下
首先要引入待測試的類import junit
[
From:http://tw.wingwit.com/Article/program/Java/ky/201311/29243.html