Recall & Review
beginner
What is the purpose of the
@Test annotation in JUnit?The
@Test annotation marks a method as a test method that JUnit will run automatically during testing.Click to reveal answer
beginner
Can a method without
@Test annotation be run as a test in JUnit?No, only methods annotated with
@Test are recognized and run as tests by JUnit.Click to reveal answer
intermediate
How do you indicate that a test method is expected to throw an exception using
@Test?You add the
expected parameter to @Test, for example: @Test(expected = IllegalArgumentException.class).Click to reveal answer
beginner
What happens if a test method annotated with
@Test fails an assertion?JUnit marks the test as failed and reports the failure in the test results.
Click to reveal answer
intermediate
Is it possible to run a test method multiple times automatically using
@Test alone?No,
@Test alone does not support running a test multiple times. You need additional tools or annotations like @RepeatedTest in JUnit 5.Click to reveal answer
What does the
@Test annotation do in JUnit?✗ Incorrect
@Test tells JUnit to run the method as a test.How do you specify that a test should expect an exception using
@Test?✗ Incorrect
The
expected parameter defines the exception the test should expect.If a method is not annotated with
@Test, what happens when you run JUnit tests?✗ Incorrect
Only methods with
@Test are run as tests.What is the default behavior if a test method annotated with
@Test throws no exception and all assertions pass?✗ Incorrect
If no exceptions occur and assertions pass, the test passes.
Which JUnit annotation is used to run a test multiple times, not
@Test?✗ Incorrect
@RepeatedTest is used in JUnit 5 to run tests multiple times.Explain the role of the
@Test annotation in JUnit testing.Think about how JUnit knows which methods to test.
You got /3 concepts.
Describe how you can use the
@Test annotation to check if a method throws an expected exception.Focus on the parameters inside the annotation.
You got /3 concepts.