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?
✗ Incorrect
The correct annotation to mark a test method in JUnit is
@Test.What does
assertEquals(5, 2 + 3) check in a JUnit test?✗ Incorrect
It checks if the sum of 2 + 3 equals 5.
What happens if an assertion in a JUnit test fails?
✗ Incorrect
If an assertion fails, JUnit marks the test as failed and shows an error.
Which of these is a good practice for writing JUnit tests?
✗ Incorrect
Testing one small thing per method makes tests clear and easy to fix.
What is the minimum Java version required to run JUnit 5 tests?
✗ Incorrect
JUnit 5 requires at least Java 8 to run.
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.