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.9. JUnit Assertions
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 does the method assertEquals do?
Hint
Think about what you compare in your tests.
- 2.
Write an assertion to check if a variable x is equal to 10.
Hint
Use assertEquals with expected value first.
- 3.
What method do you use to check if two values are equal?
- assertEqual
- assertEquals
- checkEqual
Hint
Think about the naming convention for checks.
- 4.
True or False: assertTrue checks if a condition is false.
- True
- False
Hint
Remember what assertTrue signifies.
- 5.
Write a unit test that uses assertEquals to compare two calculated values potentially returned from methods.
Hint
Think about what you expect from the calculations.
- 6.
How would you structure a test using assertThrows to ensure a method throws an exception for invalid input?
Hint
Consider how your method handles invalid data.
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