Food waste is being remade into fashion

Businesses are finding new ways to put some of the world’s 1.3 billion tons of wasted food to good use: taking the fibers from food and turning them into fabric. You read that right. Instead of…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Test Driven Development with Espresso

Human input in the software and application development life cycle is irreplaceable. But, this doesn’t override the fact that humans are susceptible to making costly mistakes. By including tests with your code, you can ensure that your code additions work and that later changes don’t break them.

Test-Driven Development, also known as TDD, is one way of ensuring to include tests with any new code. TDD could be applied on a software-development, whether it’s iOS, Android, back-end, front-end, etc.

In Android, there are 2 directories where the tests are written, Unit Tests and Instrumental Tests. Unit Test can’t test the UI without mocking objects such as an Activity, meanwhile Instrumental Test are used for testing framework such as UI. Today, automation tools and testing frameworks that allow us to create UI tests without writing any test code are there to supplement our efforts. Espresso, which is made by Google, is a testing framework designed to provide a fluent API writing concise and reliable UI test. However, it is often the case that developers are reluctant to add UI tests to their app or simply do not have time to learn the framework. Espresso lets you create and add UI tests to an existing app in an interactive way. Android Studio 2.3 is promoting it to be stable with a few enhancements.

Espresso helped me and my team to implement TDD on our Software Engineering Project. I would like to share how to use the Record Espresso Test for Instrumental Test in Android project.

In Android Studio 2.3, only few most common assertions are available through the recorder UI. You need to edit the generated code by hand if you need anything more complicated than the available assertions. The test recorder cannot handle all situations where additional synchronization is needed to deal with delays and asynchronous operations in your app.

Implementation TDD in My Project

At this stage, I made an Instrumented Test for each element of UI for Sign In page. So, I was testing the email form, password form, and sign in button. This test should fail the Git pipeline. This commit has to be consequent with the result of the Git pipeline.

[RED] <commit-message>
Example of element of my UI

For the green stage, I made an implementation for passing the Instrumented Test I’ve made. So, I made the UI for Sign In page with the elements that matched with elements in the testing. Then the GREEN implementation will make it pass the Git pipeline. This commit also has to be consequent with the result of the Git pipeline.

[GREEN] <commit-message>

The last stage, REFACTOR, for every implementation that changed the code. I’ve changed several codes for a little bit of improvement in UI. This commit didn’t make the result tests are failed, but still a success pipeline.

[REFACTOR] <commit-message>

The Espresso test recorder is a great way to start adding tests to your app whether you want to learn Espresso by examining the generated code or simply to quickly build a test suite which you can customise later. It is also great for who has not ever tried UI testing.

Happy testing :)

Add a comment

Related posts:

Why has meditation recently become popular?

You may be wondering why mindfulness seems to have become a buzzword in the past couple of years, with more companies offering mindfulness at work programs, radio shows discussing the benefits or…

Proveito das cotas

Eu tenho duas meninas que vieram da internet com essa história de gênero, de ideologia não sei o que lá. Esses dias a mais nova quis passar um vídeo numa apresentação no colégio e deu briga, até me…

Intro To Dimensional Science

Consciousness is before Existence. The Void/Non Existence/Nothingness has consciousness within it. Existence being the Light based projection that it is comes after The Void/Non…