Recall & Review
beginner
What is the main purpose of organizing test classes in JUnit?
To group related test methods logically, making tests easier to read, maintain, and run efficiently.
Click to reveal answer
beginner
How should test methods be named in a JUnit test class?
Test methods should have clear, descriptive names that explain what behavior or feature they are testing.
Click to reveal answer
intermediate
Why is it important to keep test classes focused on a single class or feature?Focusing on one class or feature per test class helps isolate failures and makes debugging easier.Click to reveal answer
beginner
What JUnit annotation is used to run setup code before each test method?
The @BeforeEach annotation is used to run setup code before every test method in the class.
Click to reveal answer
intermediate
How can you organize tests for different scenarios within the same test class?
You can group related test methods together and use comments or nested classes (JUnit 5 feature) to separate scenarios.
Click to reveal answer
What is the best practice for naming a JUnit test class?
✗ Incorrect
Naming test classes after the class they test (e.g., CalculatorTest) makes it easy to identify what is being tested.
Which annotation runs code once before all tests in a JUnit 5 test class?
✗ Incorrect
@BeforeAll runs setup code once before any test methods run, useful for expensive setup.
Why should test methods be independent in a test class?
✗ Incorrect
Independent tests ensure reliability and easier debugging because one test failure won't cause others to fail.
Where should you put common setup code for tests in a JUnit test class?
✗ Incorrect
@BeforeEach methods run before every test method, ideal for common setup.
What is a good way to organize tests for multiple features in one test class?
✗ Incorrect
Grouping related tests with nested classes or comments improves readability and maintenance.
Explain how you would organize test classes and methods for a simple calculator application using JUnit.
Think about how to keep tests clear and easy to maintain.
You got /4 concepts.
Describe the benefits of using @BeforeEach and @BeforeAll annotations in JUnit test class organization.
Consider how setup affects test reliability and speed.
You got /4 concepts.