@Target(value={FIELD,METHOD}) @Retention(value=RUNTIME) public @interface Duration
Intercept annotation in that it intercepts the call to the methods
of the Class annotated with Duration annotation. But it has got extra attributes for the user to specify the
maximum duration a method under test should take to execute.
If the total time taken by the method exceeds the time specified (using the attribute timeInMillis),
the test method will fail.
class TestClass {
@Duration(timeInMillis=100)
private ItemService testSubject;
}
MethodIntercepter :
class TestClass {
@Duration(timeInMillis=100 , interceptor=MyCustomInterceptor.class)
private ItemService testSubject;
}
In both the above cases, EasyTest will measure the time taken by each method of ItemService.
If the time taken by the method is more than the time specified, the test will fail with appropriate failure reason.
class TestClass {
private ItemService testSubject;
@Test
@Duration(forClass=ItemService.class , timeInMillis=50)
private Item testGetItem(@Param(name='itemId') String itemId) {
return testSubject.getItem(itemId);
}
}
In this case, EasyTest will compare the time taken, by the method under test, with the time specified in the Duration annotation,
only for this test method.
class TestClass {
@Duration(timeInMillis=100)
private ItemService testSubject;
@Test
@Duration(forClass=ItemService.class , timeInMillis=50)
private Item testGetItem(@Param(name='itemId') String itemId) {
return testSubject.getItem(itemId);
}
}
In this case, EasyTest will override the timeInMillis value supplied at the field level, with the value supplied at the method level.
Once the method is finished, it will revert back to the original value specified at the field level. Thus if you have second test method
that does not have Duration annotation, then the measure of time taken by the method will be 100 milliseconds and not 50 ms.| Modifier and Type | Required Element and Description |
|---|---|
long |
timeInMillis
The time in milliseconds.
|
| Modifier and Type | Optional Element and Description |
|---|---|
Class<?> |
forClass
The Class that should be proxied to provide the time comparison functionality.
|
Class<? extends MethodIntercepter> |
interceptor
The
MethodInterceptor to use to intercept method calls. |
public abstract long timeInMillis
public abstract Class<?> forClass
public abstract Class<? extends MethodIntercepter> interceptor
MethodInterceptor to use to intercept method calls.Copyright © 2014. All rights reserved.