Recall & Review
beginner
What is the main purpose of unit testing?
Unit testing checks small parts of code, like functions or methods, to make sure they work correctly on their own.
Click to reveal answer
beginner
In JUnit, what annotation marks a method as a test?
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 matches the expected result. If they are not equal, the test fails.
Click to reveal answer
intermediate
Why should unit tests be independent from each other?
Tests should not depend on others so that one test failing does not cause others to fail. This keeps tests reliable and easy to fix.
Click to reveal answer
beginner
How do you run JUnit tests in an Android Kotlin project?
You run JUnit tests using Android Studio's test runner or Gradle commands. Tests run on the JVM without needing an Android device.
Click to reveal answer
Which annotation is used to mark a method as a test in JUnit?
✗ Incorrect
The
@Test annotation marks a method as a test method in JUnit.What does
assertTrue(condition) check in a JUnit test?✗ Incorrect
assertTrue(condition) checks if the condition is true; if not, the test fails.Why is it important for unit tests to be fast?
✗ Incorrect
Fast tests allow developers to run them frequently and get quick feedback on code changes.
Which of these is NOT a good practice in unit testing?
✗ Incorrect
Unit tests should not rely on external services to avoid flakiness and keep tests fast.
In Android Kotlin projects, where are JUnit unit tests usually placed?
✗ Incorrect
JUnit unit tests are placed in
src/test/java to run on the JVM without an Android device.Explain how to write a simple JUnit test method in Kotlin for a function that adds two numbers.
Think about the structure: annotation, method, call, assertion.
You got /4 concepts.
Describe why unit tests are important in Android app development and how JUnit helps.
Focus on benefits and JUnit features.
You got /4 concepts.