JUnit5 Flashcards
What is @Timeout
used for?
@Timeout
is used to define a timeout for a test method or a test class
What is @RepeatedTest
used for?
@RepeatedTest
is used to repeat a test method a specified number of times
What is @BeforeEach
used for?
@BeforeEach
is used to run code before each test method
What is @AfterEach
used for?
@AfterEach
is used to run code after each test method
What is @BeforeAll
used for?
@BeforeAll
is used to run code once before all test methods
What is @AfterAll
used for?
@AfterAll
is used to run code once after all test methods
What is @Disabled
used for?
@Disabled
is used to disable a test method from running
What is @ParameterizedTest
used for?
@ParameterizedTest
is used to signal that a test method has parameters
True or False
Although true unit tests typically should not rely on the order in which they are executed, there are times when it is necessary to enforce a specific test method execution order
True
True or False
By default, JUnit creates a new instance of each test class before executing each test method
True
True or False
Test classes, test methods, and lifecycle methods are not required to be public and cannot be private
True
What must be done to be able to declare @BeforeAll and @AfterAll as non-static methods?
The test class must be annotated with @TestInstance(Lifecycle.PER_CLASS)
True or False
@Timeout annotations declared at the class level are also applied to lifecycle methods
False
True or False
@ExtendWith may also be declared on fields or on parameters in test class constructors, in test methods, and in @BeforeAll, @AfterAll, @BeforeEach, and @AfterEach lifecycle methods
True
Valid or invalid
@ExtendWith({ DatabaseExtension.class, WebServerExtension.class }) class MyFirstTests { // ... }
Valid