posts - 0,  comments - 3,  trackbacks - 0

package jalion.uit;

import static org.junit.Assert.*; //JDK5的新特性,静态引用,调用方法时,只写方法名就行.例如下文的assertEquals();

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.Ignore;
import org.junit.internal.runners.TestClassRunner;
import org.junit.runner.RunWith;

/*
 * @RunWith(Parameterized.class) 类标识
 *  @Parameters 方法标识.参数
*/

@RunWith(TestClassRunner.class)
public class CalculatorTest {

 @BeforeClass
 public static void setUpBeforeClass() throws Exception {
  System.out.println("类初始化时执行一次,必须是public static");
 }

 @AfterClass
 public static void tearDownAfterClass() throws Exception {
  System.out.println("运行结束时执行一次,必须是public static ");
 }

 @Before
 public void setUp() throws Exception {
  System.out.println("每次执行一个测试方法之前时,执行一次");
 }

 @After
 public void tearDown() throws Exception {
  System.out.println("每次执行完一个测试方法之后,执行一次");
 }

 @Test
 public void testAdd() {
  System.out.println("这是一个测试方法,用@Test标识, @Test(timeout = 1000) 表示执行1000毫秒,对于循环用");
  assertEquals(5,5);//查看预期结果和测试结果是否相同 是Assert的方法
 }

 @Ignore("暂时忽略")
 @Test
 public void testSubstract() {
  System.out.println("这个是暂时忽略的");
  assertEquals(5,5);
 }

 @Test(expected = ArithmeticException.class)
 public void testDivide() {
  System.out.println("异常测试,是否抛出指定异常");
  assertEquals(5,6/0);
 }

}

第二个类

package jalion.uit;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;

@RunWith(Suite.class)//runner 运行器
@Suite.SuiteClasses({  //标注为打包测试类 参数为想要测试的类
        CalculatorTest.class,
        //CalculatorTest2.class
        })
public class AllTests {
}


 

posted on 2007-07-01 10:15 李桢 阅读(426) 评论(0)  编辑  收藏 所属分类: java
<2025年7月>
293012345
6789101112
13141516171819
20212223242526
272829303112
3456789

留言簿(1)

文章分类

文章档案

搜索

  •  

最新评论