Recall & Review
beginner
What is the purpose of
assertEquals(expected, actual) in Kotlin tests?It checks if the
actual value is equal to the expected value. If not, the test fails.Click to reveal answer
beginner
How does
assertTrue(condition) work in Kotlin test assertions?It verifies that the
condition is true. If the condition is false, the test fails.Click to reveal answer
beginner
What does
assertNotNull(value) check in Kotlin tests?It checks that the
value is not null. If it is null, the test fails.Click to reveal answer
intermediate
Explain the use of
assertFailsWith<ExceptionType> { ... } in Kotlin tests.It verifies that the code inside the block throws an exception of type
ExceptionType. If no exception or a different type is thrown, the test fails.Click to reveal answer
intermediate
What is the difference between
assertEquals and assertSame in Kotlin?assertEquals checks if two objects are equal in value, while assertSame checks if they are the exact same object (reference equality).Click to reveal answer
Which assertion checks if a condition is true in Kotlin tests?
✗ Incorrect
assertTrue(condition) verifies that the condition is true.What happens if
assertEquals(expected, actual) fails?✗ Incorrect
If the values are not equal, the test fails and reports the difference.
Which assertion would you use to check that a variable is not null?
✗ Incorrect
assertNotNull(value) ensures the value is not null.How do you test that a block of code throws a specific exception in Kotlin?
✗ Incorrect
assertFailsWith<Exception> { } checks for a specific exception.What does
assertSame(obj1, obj2) check?✗ Incorrect
assertSame checks if both references point to the exact same object.Describe how you would use Kotlin test assertions to verify that a function returns the expected value and does not return null.
Think about checking value equality and null separately.
You got /4 concepts.
Explain how to test that a Kotlin function throws a specific exception when given invalid input.
Focus on the assertion that expects an exception.
You got /3 concepts.