junit的入门

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);
  }
 }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值