http://www.cntesting.com/pic/study/JUnitGossip/TestSuite.htm
package com;
public class Test1 {
public String str(String str){
return str;
}
}
package com;
import junit.framework.TestCase;
public class Test1Test extends TestCase {
private Test1 test1;
protected void setUp() throws Exception {
super.setUp();
test1 = new Test1();
}
protected void tearDown() throws Exception {
super.tearDown();
}
/*
* “com.Test1.str(String)”的测试方法
*/
public void testStr() {
assertEquals("nn",test1.str("nn"));
}
}
package com;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
public class TestMore extends TestCase {
public static Test suite(){
TestSuite suite = new TestSuite("TestMore");
suite.addTestSuite(Test1Test.class);
return suite;
}
}
package com;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
public class TestAll extends TestCase {
public static Test suite(){
TestSuite suite = new TestSuite();
suite.addTest(TestMore.suite());
return suite;
}
}
package today;
public class T1 {
public int test(int num){
return num;
}
}
package today;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
public class T1Test extends TestCase {
public T1 t1;
protected void setUp() throws Exception {
super.setUp();
t1 = new T1();
}
protected void tearDown() throws Exception {
super.tearDown();
}
public void testTest() {
assertEquals(t1.test(4),4);
}
public static Test suite(){
TestSuite suite = new TestSuite();
suite.addTestSuite(T1Test.class);
return suite;
}
}
package today;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
public class TestAll {
public static Test suite(){
TestSuite suite = new TestSuite();
suite.addTest(T1Test.suite());
return suite;
}
}
/**
* 测试当生成direction的方法传入的是'1'和'2'之外的字符时抛出自定义RangeException异常
*/
public void testGenerateDirectionException1()
{
try
{
httpDataHandler.generateDirection('0');
fail("Should hava thrown a rangeException");
}
catch(Exception e)
{
assertTrue(true);
}
}