0
0
JUnittesting~5 mins

@Test annotation in JUnit - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
AMarks a method to run before all tests
BMarks a method to be ignored
CMarks a method as private
DMarks a method to be run as a test
How do you specify that a test should expect an exception using @Test?
AUse <code>@Test(expected = Exception.class)</code>
BUse <code>@Test(timeout = 1000)</code>
CUse <code>@Test(ignore = true)</code>
DUse <code>@Test(repeat = 3)</code>
If a method is not annotated with @Test, what happens when you run JUnit tests?
AThe method runs as a test anyway
BThe method is not run as a test
CJUnit throws an error
DThe method runs before tests
What is the default behavior if a test method annotated with @Test throws no exception and all assertions pass?
ATest passes
BTest fails
CTest is ignored
DTest is skipped
Which JUnit annotation is used to run a test multiple times, not @Test?
A<code>@Test(repeat = 3)</code>
B<code>@TestMultiple</code>
C<code>@RepeatedTest</code>
D<code>@RunMultiple</code>
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.