Annotations Flashcards
@ParameterizedTest
These tests make it possible to run a test multiple times with different arguments.
In addition, you must declare at least one source that will provide the arguments for each invocation and then consume the arguments in the test method.
@ParameterizedTest - visual
@ParameterizedTest
@ValueSource(strings = { “racecar”, “radar”, “able was I ere I saw elba” })
void palindromes(String candidate) {
assertTrue(StringUtils.isPalindrome(candidate));
}
palindromes(String) ✔
├─ [1] candidate=racecar ✔
├─ [2] candidate=radar ✔
└─ [3] candidate=able was I ere I saw elba ✔
@ValueSource
It’s one of the simplest possible sources. It lets you specify a single array of literal values and can only be used for providing a single argument per parameterized test invocation
@Disabled
Used to disable a test class or test method; analogous to JUnit 4’s @Ignore. Such annotations are not inherited.
@Disabled(“Disabled until bug #99 has been fixed”)
@Timeout
allows one to declare that a test, test factory, test template, or lifecycle method should fail if its execution time exceeds a given duration.
@Test
@______(value = 500, unit = TimeUnit.MILLISECONDS, threadMode = ThreadMode.SEPARATE_THREAD)
void failsIfExecutionTimeExceeds500MillisecondsInSeparateThread() {
// fails if execution time exceeds 500 milliseconds, the test code is executed in a separate thread
}