注释类型(annotation type)

[url]http://www.junit.org/apidocs/org/junit/Test.html[/url]

The Test annotation tells JUnit that the public void method to which it is attached can be run as a test case. To run the method, JUnit first constructs a fresh instance of the class then invokes the annotated method. Any exceptions thrown by the test will be reported by JUnit as a failure. If no exceptions are thrown, the test is assumed to have succeeded.

-----------------------------------------


package test;
import org.junit.Test;

public class Test03 {
@Test public void ttt()
{
System.out.println("ttt ttt");
}
}


junit 以两种方式启动:
1、TestCase
2、@Test

后者参见
[url]http://www.ibm.com/developerworks/cn/java/j-lo-junit4/[/url]

测试类 TestWordDealUtil 之所以使用“Test”开头,完全是为了更好的区分测试类与被测试类。测试方法 wordFormat4DBNormal 调用执行被测试方法 WordDealUtil.wordFormat4DB,以判断运行结果是否达到设计预期的效果。需要注意的是,测试方法 wordFormat4DBNormal 需要按照一定的规范书写:

1. 测试方法必须使用注解 org.junit.Test 修饰。
2. 测试方法必须使用 public void 修饰,而且不能带有任何参数。

-------------------------------------------------------
[url]http://developer.51cto.com/art/200909/152828.htm[/url]

Java语言支持一种新的类型——注释类型(annotation type),跟普通类差不多,在类中以符号( @ )的形式注释其他 Java 代码

简单的注释类型
public @interface InProgress { }

junit 里

package org.junit;
public @interface Test {

----------------------------------------------------
[url]http://tech.sina.com.cn/s/2008-07-07/08532307714.shtml[/url]
  此外,注释另外一个很成功的应用可能就是在JUnit4 API里的应用。如:

  增加一个@Test注释,而不需要像以前那样写成testXxx();

  增加一个@Test注释,就可以替代以前的try/catch出错处理了;

  增加一个@Before@After注释,可以替换以前的setUp()等方法;

  增加一个@RunWith(Parameterized.class)及一个方法@Parameters public static Collection parameters(),被测试类的构造参数都保存在Object[]里。这样就进行参数化的测试了,而无须像从前那样public static Test suite()。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值