0
0
Android Kotlinmobile~5 mins

Unit testing with JUnit in Android Kotlin - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
A@Test
B@Run
C@Check
D@Verify
What does assertTrue(condition) check in a JUnit test?
AThat the condition is false
BThat an exception is thrown
CThat two values are equal
DThat the condition is true
Why is it important for unit tests to be fast?
ASo they can run often and give quick feedback
BBecause slow tests are more accurate
CTo use more CPU resources
DTo make debugging harder
Which of these is NOT a good practice in unit testing?
ATesting one thing per test
BRelying on external services in tests
CMaking tests independent
DUsing clear test names
In Android Kotlin projects, where are JUnit unit tests usually placed?
Asrc/androidTest/java
Bsrc/main/java
Csrc/test/java
Dsrc/resources
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.