Enrol to start learning
Reading is open to everyone. Enrolling is free, and it is what unlocks the audio lessons, practice tests and progress tracking.
25.4. Anatomy of a Unit Test
This section
Practice test
12 questions on this section. Wrong answers show you what to read again.
Sign up to take itWhole chapter
Revision test
Mixed questions from across the chapter. Your answers get marked.
Sign up to take itQuick
Flashcard drill
4 cards from this lesson. Good the night before a test.
Try these first
- 1.
What is the purpose of the setup component in a unit test?
Hint
Think about what you need to ensure everything is ready before the test.
- 2.
Name one assertion method you can use in JUnit.
Hint
Recall what methods we use to check for expected results.
- 3.
What phase follows setup in a unit test?
- Teardown
- Execution
- Assertion
Hint
Think about the order of operations in a test.
- 4.
True or False: Teardown is mandatory in every unit test.
- True
- False
Hint
Consider if cleanup is needed for all tests.
- 5.
Design a unit test that measures the performance of a sorting function, including all phases: setup, execution, assertion, and teardown.
Hint
Consider how to verify that the array is sorted correctly post-execution.
- 6.
Create a scenario where tests may fail due to an improper setup phase. What could happen?
Hint
Think about how initial conditions impact the functionality being tested.
Exercises
Total Questions
2
Estimated Time
4 min
Passing Score
70%
Instructions
- Read each question carefully
- You can use hints if you need help
- Complete all questions before submitting
4 more questions available
Enrol freeQuiz
Total Questions
2
Estimated Time
4 min
Passing Score
70%
Instructions
- Read each question carefully
- You can use hints if you need help
- Complete all questions before submitting
2 more questions available
Enrol freeChallenge Problems
Total Questions
2
Estimated Time
4 min
Passing Score
70%
Instructions
- Read each question carefully
- You can use hints if you need help
- Complete all questions before submitting