Difference 1: @Test annotation in junit5 do not have any attributes.
@Target({ ElementType.ANNOTATION_TYPE, ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
@Documented
@API(status = STABLE, since = "5.0")
@Testable
public @interface Test {
}
In Junit4, @Test annotation has attributes and defined like below.
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD})
public @interface Test {
Class<? extends Throwable> expected() default None.class;
long timeout() default 0L;
}
Difference 2: In Junit4, Test class and test method should be public. In Junit5, neither test class, not test method need to be public.
Below snippet runs well in junit5, but not in junit 4.
class AppTest {
@Test
public void helloTest() {
assertTrue(true);
}
}
No comments:
Post a Comment