01: package org.junit;
02:
03: import java.lang.annotation.ElementType;
04: import java.lang.annotation.Retention;
05: import java.lang.annotation.RetentionPolicy;
06: import java.lang.annotation.Target;
07:
08: /**
09: * <p>The <code>Test</code> annotation tells JUnit that the <code>public void</code> method
10: * to which it is attached can be run as a test case. To run the method,
11: * JUnit first constructs a fresh instance of the class then invokes the
12: * annotated method. Any exceptions thrown by the test will be reported
13: * by JUnit as a failure. If no exceptions are thrown, the test is assumed
14: * to have succeeded.</p>
15: *
16: * <p>A simple test looks like this:
17: * <pre>
18: * public class Example {
19: * <b>@Test</b>
20: * public void method() {
21: * org.junit.Assert.assertTrue( new ArrayList().isEmpty() );
22: * }
23: * }
24: * </pre>
25: * </p>
26: *
27: * <p>The <code>Test</code> annotation supports two optional parameters.
28: * The first, <code>expected</code>, declares that a test method should throw
29: * an exception. If it doesn't throw an exception or if it throws a different exception
30: * than the one declared, the test fails. For example, the following test succeeds:
31: * <pre>
32: * @Test(<b>expected=IndexOutOfBoundsException.class</b>) public void outOfBounds() {
33: * new ArrayList<Object>().get(1);
34: * }
35: * </pre></p>
36: *
37: * <p>The second optional parameter, <code>timeout</code>, causes a test to fail if it takes
38: * longer than a specified amount of clock time (measured in milliseconds). The following test fails:
39: * <pre>
40: * @Test(<b>timeout=100</b>) public void infinity() {
41: * while(true);
42: * }
43: * </pre></p>
44: */
45: @Retention(RetentionPolicy.RUNTIME)
46: @Target(ElementType.METHOD)
47: public @interface Test {
48:
49: /**
50: * Default empty exception
51: */
52: static class None extends Throwable {
53: private static final long serialVersionUID = 1L;
54:
55: private None() {
56: }
57: }
58:
59: /**
60: * Optionally specify <code>expected</code>, a Throwable, to cause a test method to succeed iff
61: * an exception of the specified class is thrown by the method.
62: */
63: Class<? extends Throwable> expected() default None.class;
64:
65: /**
66: * Optionally specify <code>timeout</code> in milliseconds to cause a test method to fail if it
67: * takes longer than that number of milliseconds.*/
68: long timeout() default 0L;
69: }
|