Testing based Android interview questions and answers
What is Test Module?
A) Module that contains the source code to test application projects and is built into test application that run on a device
What is JUnit?
A) A unit testing framework for the Java programming language
What is TDD (Test-driven development)?
A) A software development process that relies on the repetition of a very short development cycle: first an automated test case is written that defines a desired improvement of new function
What is Test case?
A) Set of conditions under which a tester will determine whether an application, software system or one of features is working as was originally established for it to do
What is the difference between unit testing and instrumentation testing?
- Unit testing:
- All unit tests bypass the Android system and run straight on the developer machine.
- Unit tests cannot use much of the Android SDK
- Unit tests run quickly
- Unit tests are placed inside the “test” folder
- Instrumentation testing:
- Test code and production code combined is running in a single process in a single copy of the VM (Dalvik or ART)
- Instrumentation tests are placed inside the “androidTest” folder
What is Test Module?
A) Module that contains the source code to test application projects and is built into test application that run on a device
What is JUnit?
A) A unit testing framework for the Java programming language
Where Do You Organize Your Tests in Android?
When you create an Android Studio project, you create two directories for testing:
- The
test
directory is for unit tests that run locally. Usually, the JVM runs these tests. - The
androidTest
directory is for tests that run on devices. You’ll use this directory for other kinds of tests, such as integration tests and end-to-end tests.
What Are Unit Tests? How Do You Do Them in Android?
Unit tests run locally. Since they aren’t run on a device, they don’t have access to any Android framework library. It’s possible to use libraries that allow you to call Android framework methods from unit tests, however these libraries substitute only simulate device behavior. The preferred libraries are either JUnit or Mockito.
The ability to design and implement unit testing is usually a requirement for mid-senior to senior levels. If you want to learn how to do this, here are some resources:
- JUnit is the standard java library for testing, which is usually coupled with AndroidX Test. This is covered in our tutorial Test-Driven Development Tutorial for Android: Getting Started.
- Mockito is another popular open-source testing framework. You can learn more about it in our tutorial Android Unit Testing with Mockito.
Understanding how to use either of these test libraries will be enough for interviews.
Instrumentation Tests
Instrumentation tests are quite similar to unit tests but depend on a device or simulator to run. Since instrumentation tests are run on device, you have access to the Android device libraries. The two libraries mentioned above, JUnit and Mockito, are also used for instrumentation tests.
UI Tests
UI tests simulate a user’s interactions with your UI. The most popular library for testing is Espresso. You can learn about UI testing in our tutorial
Espresso Testing and Screen Robots: Getting Started.
Explain the JUnit test in brief.
JUnit is a “Unit Testing” framework for Java Applications which is already included by default in android studio. It is an automation framework for Unit as well as UI Testing. It contains annotations such as @Test, @Before, @After, etc. Here we will be using only @Test annotation to keep the article easy to understand.
To read more, refer to the article: Unit Testing in Android using JUnit
Comments
Post a Comment