![]() |
VOOZH | about |
We’re so glad you’re here. You can expect all the best TNS content to arrive Monday through Friday to keep you on top of the news and at the top of your game.
Check your inbox for a confirmation email where you can adjust your preferences and even join additional groups.
Follow TNS on your favorite social media networks.
Become a TNS follower on LinkedIn.
Check out the latest featured and trending stories while you wait for your first TNS newsletter.
Software development involves process and people. The people include both technical and nontechnical stakeholders, but because the process is primarily technical, it can create a large gap between technical and nontechnical stakeholders.
Bridging this gap requires a collaborative approach that uses natural language to encourage communication and collaboration between technical and nontechnical stakeholders. This is precisely what behavior-driven development (BDD) aims for: to bring a point of understanding among developers, testers and business stakeholders.
As a software engineer, I’ve been implementing BDD using one of the most popular tools, Cucumber. Cucumber helps business and technical teams work together by collaborating on executable specifications. The BDD specifications also double as automated tests. Using the Gherkin framework, these specifications are written collaboratively, aligning the team with living documentation of your system’s work.
In this article, I will explain five simple steps for integrating Cucumber testing into your Android application.
Let’s dive into setting up Android Studio for Cucumber Tests.
Before you start, make sure you have the Android Studio integrated development environment (IDE) installed.
You can also consider installing the following plug-ins from the Android Studio marketplace:
Create a new Android Studio Project in your IDE, or use an existing one. Next, add the Cucumber dependencies.
In your app-level module build.gradle file, add the following dependencies:
In app/src/androidTest/java/com/your/app/, create a custom instrumentation runner named CucumberTestInstrumentation.java. Add this class to your build.gradle under android > defaultConfig:
You have successfully set up Android Studio for Cucumber, so you can now proceed to the exciting part.
Gherkin is a domain-specific language that describes the implementation of a feature step by step using nontechnical terms. It uses the keywords Given, When, And and Then to explain the steps. These steps can be written in any human-spoken language, such as English, Arabic or Luo.
Here is an example Gherkin feature scenario written in English that I will use in this project:
Create an assets directory in app/src/androidTest/assets and add a folder called features. This is where you will add your feature file containing the above step definitions written in English.
Add a new .feature file called login.feature and add the feature steps above.
In app/src/androidTest/java/com/your/app/, create a Kotlin class called LoginSteps. This is where you will write your tests to implement the steps in login.feature.
Here is a code snippet of the implementation of the steps:
Before running your tests, you must provide the packages containing the step definitions and glue them to your steps.
In app/src/androidTest/java/com/your/app, create a folder called test and add a new Kotlin class.
Finally, you can run your test, but first, confirm your project structure looks like this:
To run your tests:
Android Instrumented Tests.Ability of the customer to login. Then click Run or OK to run or debug it later from the IDE toolbar.Here is the result of the implementation above.
Bridging the gap between technical and nontechnical stakeholders is crucial for effective software development. Behavior-driven development facilitates collaboration and communication in natural language.
Tools like Cucumber help implement BDD using executable specifications as automated tests, allowing teams to create clear, shared documentation. Integrating Cucumber into your Android application development can enhance team alignment and streamline development.
For more insight, access my Hechio BDD reference project or the cucumber/cucumber-android project, which provides Android support for Cucumber-JVM.
Want to dive deeper into Android development? Check out Andela’s tutorial (also written by Stephen Henry) on Android ML face detection with Camera X.