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?

  1. 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
  2. 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

CAN YOU MENTION SOME TYPES OF TESTING YOU KNOW?
An Android application can typically run different tests:
-UI Tests: they involve user interaction, and verifies that an app is behaving correctly in
different scenarios with different data.
-Unit Test: Unitary test are based in the JUnit framework, and they can test the output of
any class: checking that a manager is correctly handling a set of mocked data, or that is
producing the right output.
-Integration Test: they verify that the integration and collaboration between different
modules is effective and working.

DO YOU HAVE EXPERIENCE WITH LINT? WHY IS IT USED FOR?
Lint is a tool that scans the code statically and can provide a report with potential bugs,
issues with the code style and tips about optimization and performance.
Lint is integrated in IDEs such as Android Studio, but it can also be run from the
command line or integrated in a Continuous Integration server.

IN AN INSTRUMENTATION TESTCASE, WHAT ARE THE TWO MOST
IMPORTANT METHODS?
An Android Intrumentation Test implements two very important methods
protected void setUp ()
protected void tearDown ()
setUp() runs before it test it is realized to initialize the testing environment. tearDown()
runs immediately after, so it can close connection or restore the status of the testing
environment.
BONUS:
The setUp() functions is always called before each individual test is passed. A
confident developer will know that if we run two different tests, this will be the
execution flow:
constructor()
setUp();
testXXX();
tearDown();
setUp();
testXXX2();
tearDown();

 HOW ANDROID KNOWS THAT A FUNCTION IN A FILE IS A TEST THAT
NEEDS TO BE RUNNED?
Using reflection. Android looks inside a test file for all the functions that start with the
prefix “test”, and run them. If you try with a function called pleaseRunThisFunction() it
will not run.

THERE ARE TWO BIG LIBRARIES USED FOR ANDROID TESTING, ESPRESSO
AND ROBOTIUM. CAN YOU MENTION ONE BIG ADVANTAGE OF ESPRESSO OVER
ROBOTIUM?
The major one is that Espresso is synchronized, whether Robotium is not. That means
that many times a test developed with Robotium will just failed because an UI has not
been updated but the test is expecting to perform a click or interact with the user screen.
A better error reporting and a clearer API are reasons that some people might agree or
not, but the synchronization is a objective major difference.

THERE ARE TWO BIG LIBRARIES USED FOR ANDROID TESTING, ESPRESSO
AND ROBOTIUM. CAN YOU MENTION ONE BIG ADVANTAGE OF ESPRESSO OVER
ROBOTIUM?
The major one is that Espresso is synchronized, whether Robotium is not. That means
that many times a test developed with Robotium will just failed because an UI has not
been updated but the test is expecting to perform a click or interact with the user screen.
A better error reporting and a clearer API are reasons that some people might agree or
not, but the synchronization is a objective major difference.

Where Do You Organize Your Tests in Android?

When you create an Android Studio project, you create two directories for testing:

  1. The test directory is for unit tests that run locally. Usually, the JVM runs these tests.
  2. 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:

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


Aaaaaa

Comments

Popular posts from this blog

Jetpack Compose based Android interview and questions

Null safety based Kotlin interview questions and answers

CustomView based Android interview questions and answers