In this post, we are going to learn about existing types of tests that could be carried out in order to make sure a function is correctly developed and implemented on a software.

Then, we will focus on Android Testing; in particular on the two most common Android tests used in Android Studio.

Tests

Tests are one of the most important tasks a programmer can do, since they can help us find bugs or make sure a function is correctly developed. In my personal experience, just a few codes worked 100% as expected without the need of tests. Trusting yourself, without validating the function through a 2-minute test, can definitely ruin the user experience and many hours of work.

Since programming began, tests have been developed and used to test many different aspects of programs. For instance, from e-commerce transactions to graphic changes on UI.

A test can be located in diverse categories depending on the aspect we want to focus on. Anyway, some famous sources such as Ian Sommerville have contributed to precisely categorize the types of test. Which have also been well received by other developers.

Some of the most common tests mentioned in his book (Software Engineering) are Unit tests, Component tests, and System tests. Those three tests are used during the software development to keep constantly checking its functionality. This way of testing is called Development Testing.

  • Unit tests tries to verify an object, class or method behaves as expected.
  • Component tests create composite tests based on individual tests that can usually be found on unit tests.
  • On System tests, the whole software is tested integrating all different components.

All those tests can be developed manually or automatically, entailing another typical testing category; ‘Manual vs Automated Testing’. Even though automated tests are gaining fame, testing will never be totally automated since there are things an automated program can’t check. For instance, these tests can never verify if a User Interface looks as expected.

Depending on the previous knowledge of the software’s code; unit, component, and system tests can usually be treated differently. This will be based on a new category of White, Grey and Black-Box tests.

On the White-Box tests, we need to consider internal system design, which can lead to avoiding testing some problematic functions or unique cases that programmers know can cause a conflict. It’s then the programmer’s job to focus on those cases in order to make sure the application is well developed.

Black-box tests, on the contrary, are those tests where internal system design is not being considered. Hence, the application is like a black box with entries and exits where the programmer has to make sure the exits are as expected for those entries.

Grey-box tests are a combination of the previous two; it mainly focuses on searching for defects due to an incorrect structure or a wrong use of applications.

Therefore, to check if a method behaves as expected through a Unit test, it will necessary be a White-Box one. Nevertheless, System tests can be developed as Black-Box tests with no need of knowing the internal processes or software’s design.

There is no way to favor a test over another, because there isn’t a better one. Meaning that, each one has its time and its place depending on the project’s conditions and the client’s needs.

When choosing a test for an app, firstly we have to understand the current condition of the app. This means we can’t perform a System test to verify the correct operation of a method, instead, it should be checked through a Unit test.

But where and how can we make our first test for an Android app?

Testing on Android

In order to create tests on Android, an Integrated Development Environment (IDE) is needed. Accordingly, any IDE supporting Java is able to create applications and tests. Even though Eclipse was the most common Java IDE, when Google developed Android Studio, it soon replaced Eclipse and has become the official Android IDE so far, allowing the use of other programming languages such as Kotlin.

Android Studio has several benefits over other IDEs, such as its user-friendliness and including some handy development frameworks. It also provides native tools which we will cover in the next post.

Illustration 1: Android Studio’s project files view.

In Android Studio a project is organized in 3 main packages: The first one is where the application code will be located, the second is where we can place Instrumented Tests, and the third one is for Unit Tests.

Since Unit Tests are made for testing a specific function, Instrumented Tests can also be made for testing more complex situations, not just a function but how it matches the others. It should be noted that Component and System tests mentioned on the previous section can be developed as Instrumented tests. An example of each Instrumented and Unit test is given when you create a project. So, you can modify those in order to make your own test.

A test is run by something called ‘Test runner’. To further elaborate, it can understand the test syntax according to some determined rules and then behave accordingly. That syntax depends on the test runner used, and although AndroidJUnitRunner is the predetermined one on Android Studio for JUnit tests (which are the most common tests on Java), it can change to another test runner, even a self-created one. This can be done through build.gradle file > DefaultConfig{ testInstrumentationRunner… }

To create your first programmatical test which does not need to check a graphical interaction with the UI, Assert Java class is commonly used on Unit Tests. We can verify if the app’s response is as expected when we interact somehow with it.

In the next post we will briefly talk about the most used frameworks and native Android tools which may help us test our applications. Some of those frameworks will help us make a graphical test where we can physically see the interaction with the app on a device.

We will also introduce an automated testing tool developed by Android, already native on the Software Development Kit (SDK) and easy to use.

CC BY-NC-ND 4.0 Android Testing por davidrtorrado está licenciado bajo una Licencia Creative Commons Atribución-NoComercial-SinDerivar 4.0 Internacional.

Deja un comentario

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *