0
0
JUnittesting~5 mins

First JUnit test - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of a JUnit test?
A JUnit test checks if a small part of your code works correctly by running it automatically and comparing the result to what you expect.
Click to reveal answer
beginner
What annotation marks a method as a test in JUnit?
The @Test annotation tells JUnit that the method below it is a test method to run.
Click to reveal answer
beginner
What does the assertion assertEquals(expected, actual) do in a JUnit test?
It checks if the actual result from the code matches the expected result. If they are equal, the test passes; if not, it fails.
Click to reveal answer
beginner
How do you write a simple JUnit test method to check if 2 + 3 equals 5?
Use @Test annotation and inside the method call assertEquals(5, 2 + 3); to check the sum.
Click to reveal answer
beginner
Why is it important to keep JUnit tests small and focused?
Small tests are easier to understand, faster to run, and help find problems quickly because they test only one thing at a time.
Click to reveal answer
Which annotation is used to mark a method as a test in JUnit?
A@Check
B@Run
C@Verify
D@Test
What does assertEquals(5, 2 + 3) check in a JUnit test?
AIf 5 equals 2 + 3 plus 1
BIf 2 + 3 is greater than 5
CIf 2 + 3 equals 5
DIf 5 is less than 2 + 3
What happens if an assertion in a JUnit test fails?
AThe test fails and reports an error
BThe test passes silently
CThe test skips the assertion
DThe test restarts automatically
Which of these is a good practice for writing JUnit tests?
ATest one small thing per test method
BTest many things in one method
CAvoid using assertions
DWrite tests only after the project is finished
What is the minimum Java version required to run JUnit 5 tests?
AJava 17
BJava 8
CJava 11
DJava 6
Explain how to write and run your first JUnit test method.
Think about the steps from writing code to checking results.
You got /4 concepts.
    Describe why assertions are important in JUnit tests.
    Assertions are like checkpoints in your test.
    You got /4 concepts.