Complete the code to register a JUnit extension using the correct annotation.
@[1] MyExtension extension = new MyExtension();The @RegisterExtension annotation is used to register an extension instance in JUnit 5.
Complete the code to implement the JUnit extension interface for before each test callback.
public class MyExtension implements [1] { }
The BeforeEachCallback interface allows code to run before each test method.
Fix the error in the extension method signature to correctly override the beforeEach method.
@Override
public void beforeEach([1] context) throws Exception { }The beforeEach method receives an ExtensionContext parameter in JUnit 5 extensions.
Fill both blanks to implement an extension that prints a message before and after each test.
public class MyExtension implements [1], [2] { @Override public void beforeEach(ExtensionContext context) { System.out.println("Starting test"); } @Override public void afterEach(ExtensionContext context) { System.out.println("Finished test"); } }
The extension implements BeforeEachCallback and AfterEachCallback to run code before and after each test.
Fill all three blanks to create a dynamic test factory method using JUnit extension.
@TestFactory
Stream<DynamicTest> dynamicTests() {
return Stream.of("A", "B", "C")
.map([1] -> DynamicTest.dynamicTest(
"Test " + [2],
() -> assertTrue([3].length() > 0)
));
}The lambda parameter is value, used to name and test each dynamic test.