@Test public void test(){ System.out.println("test"); } |
@Retention(RetentionPolicy.RUNTIME) @Target({ElementType.METHOD, ElementType.TYPE, ElementType.CONSTRUCTOR}) public @interface Test { String[] groups() default {}; boolean enabled() default true; /** @deprecated */ @Deprecated String[] parameters() default {}; String[] dependsOnGroups() default {}; String[] dependsOnMethods() default {}; long timeOut() default 0L; long invocationTimeOut() default 0L; int invocationCount() default 1; int threadPoolSize() default 0; int successPercentage() default 100; String dataProvider() default ""; Class<?> dataProviderClass() default Object.class; boolean alwaysRun() default false; String description() default ""; Class[] expectedExceptions() default {}; String expectedExceptionsMessageRegExp() default ".*"; String suiteName() default ""; String testName() default ""; /** @deprecated */ boolean sequential() default false; boolean singleThreaded() default false; Class retryAnalyzer() default Class.class; boolean skipFailedInvocations() default false; boolean ignoreMissingDependencies() default false; int priority() default 0; } |
groups |
enabled |
parameters |
dependsOnGroups |
dependsOnMethods |
invocationTimeOut |
invocationCount |
threadPoolSize |
successPercentage |
dataProvider |
dataProviderClass |
alwaysRun |
description |
expectedExceptions |
expectedExceptionsMessageRegExp |
suiteName |
testName |
sequential |
singleThreaded |
retryAnalyzer |
skipFailedInvocations |
ignoreMissingDependencies |
priority |
@Test public void shouldThrowIfPlaneIsFull() { Plane plane = createPlane(); plane.bookAllSeats(); try { plane.bookPlane(createValidItinerary ( ), null); fail(MThe reservation should have failed"); } catch(ReservationException ex) { //success, do nothing: the test will pass } } |
@Test(expectedExceptions = ReservationException.class) public void shouldThrowIfPlanelsFull() { plane plane = createPlane(); plane. bookAHSeats (); plane.bookPlane(createValidItinerary(), null); } |
public class Singleton { private static Singleton instance = null; public static Singleton getlnstance() { if (instance == null) { instance = new Singleton(); } return instance; } } |
private Singleton singleton; @BeforeClass public void init() { singleton = new Singleton(); } @Test(invocationCount = 100, threadPoolSize = 10) public void testSingleton(){ Thread.yield(); Assert.assertNull(instance); Singleton p = singleton.getlnstance(); } |
================================================== Concurrent testing Total tests run: 100, Failures: 5, Skips: 0 ================================================== |
//测试10s内运行一百次方法调用成功率是否超过98% @Test(timeOut = 10000, invocationCount = 1000, successPercentage = 98) public void waitForAnswer() { while (1 success) { Thread.sleep(1000); } } |
欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) | Powered by Discuz! X3.2 |