Android library that allows you to run your acceptance tests written in Gherkin in your Android instrumentation tests.

Overview

License Android Arsenal

Green Coffee

Green Coffee is a library that allows you to run your acceptance tests written in Gherkin in your Android instrumentation tests using the step definitions that you declare. Visit the wiki for more detailed information.

Example

Given the following feature:

Feature: Login screen to authenticate users

	Scenario: Invalid username and password
        Given I see an empty login form
         When I introduce an invalid username
          And I introduce an invalid password
          And I press the login button
         Then I see an error message saying 'Invalid credentials'

First, create a class that extends from GreenCoffeeTest and declare the Activity, the feature and the step definitions that will be used:

@RunWith(Parameterized.class)
public class LoginFeatureTest extends GreenCoffeeTest
{
    @Rule
    public ActivityTestRule<LoginActivity> activity = new ActivityTestRule<>(LoginActivity.class);

    public LoginFeatureTest(ScenarioConfig scenarioConfig)
    {
        super(scenarioConfig);
    }

    @Parameters(name = "{0}")
    public static Iterable<ScenarioConfig> scenarios() throws IOException
    {
        return new GreenCoffeeConfig()
                        .withFeatureFromAssets("assets/login.feature")
                        .takeScreenshotOnFail()
                        .scenarios(
                            new Locale("en", "GB"),
                            new Locale("es", "ES")
                        ); // the locales used to run the scenarios (optional)
    }

    @Test
    public void test()
    {
        start(new LoginSteps());
    }
}

Next, create a class containing the steps definitions:

public class LoginSteps extends GreenCoffeeSteps
{
    @Given("^I see an empty login form$")
    public void iSeeAnEmptyLoginForm()
    {
        onViewWithId(R.id.login_input_username).isEmpty();
        onViewWithId(R.id.login_input_password).isEmpty();
    }

    @When("^I introduce an invalid username$")
    public void iIntroduceAnInvalidUsername()
    {
        onViewWithId(R.id.login_input_username).type("guest");
    }

    @When("^I introduce an invalid password$")
    public void iIntroduceAnInvalidPassword()
    {
        onViewWithId(R.id.login_input_password).type("1234");
    }

    @When("^I press the login button$")
    public void iPressTheLoginButton()
    {
        onViewWithId(R.id.login_button_doLogin).click();
    }

    @Then("^I see an error message saying 'Invalid credentials'$")
    public void iSeeAnErrorMessageSayingInvalidCredentials()
    {
        onViewWithText(R.string.login_credentials_error).isDisplayed();
    }
}

And that's it, now you can create your own tests using Green Coffee. This is how it looks when you run a more complex test:

Example

You can see an example applied to a full app here.

Installation

Add the following code to your root build.gradle:

allprojects
{
    repositories
    {
        maven
        {
            url 'https://jitpack.io'
        }
    }
}

Add the following code to your module build.gradle file:

dependencies
{
    androidTestImplementation 'androidx.test:runner:1.3.0'
    androidTestImplementation 'androidx.test:rules:1.3.0'
    androidTestImplementation 'com.github.mauriciotogneri:green-coffee:3.6.0'
}

And the following test instrumentation runner:

defaultConfig
{
    testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
}
Comments
  • i have problem when integrate the green coffee library with espresso

    i have problem when integrate the green coffee library with espresso

    actully i have followed the example shared and when i have create a steps definition class and once i have extended the steps class from Greencoffee steps the link between the feature file and the steps class is lost and the run will be displayed error in runtime I am using the dependencies :- implementation 'io.cucumber:gherkin-jvm-deps:1.0.4' androidTestImplementation 'com.android.support:support-annotations:28.0.0' // androidTestImplementation 'com.android.support.test:runner:1.0.2' androidTestImplementation 'com.mauriciotogneri:greencoffee:3.5.0' // Espresso UI Testing androidTestImplementation "androidx.test.espresso:espresso-idling-resource:${espressoVersion}" androidTestImplementation ("androidx.test.espresso:espresso-core:${espressoVersion}") androidTestImplementation "androidx.test.espresso:espresso-contrib:${espressoVersion}" androidTestImplementation "androidx.test.espresso:espresso-intents:${espressoVersion}" androidTestImplementation "androidx.test.espresso:espresso-accessibility:${espressoVersion}" androidTestImplementation "androidx.test.espresso:espresso-web:${espressoVersion}"

    Screen Shot 2020-08-20 at 11 45 20 PM Screen Shot 2020-08-20 at 11 46 28 PM Screen Shot 2020-08-20 at 11 47 44 PM please advice ASAP ;)
    opened by mennatallah 22
  • Duplicate tests

    Duplicate tests

    Hello everyone! 😄

    I have a scenario outline with 5 steps, when I run the tests it appears to me this message "Starting 10 tests on Nexus2(AVD) - 9"

    Can you help me with this problem?

    this is my login.feature:

    file.txt

    and this my LoginFeatureTest.java:

    file2.txt

    opened by alastorohlin 6
  • Test names in report

    Test names in report

    Hello! Please help me with displaying real test names in report. I see only "test[0]", "test[1]" but actualy have tests: "Invalid username and password" and "Correct username and password" See screenshot: http://joxi.ru/J2b97L3SXgWYNm

    opened by vladimirandroid 5
  • Run Specific feature file

    Run Specific feature file

    Hi how can I run specific feature file or scneario.

    Example:

    Scenario1: Test1

    Scenario2: Test2

    In above case I would like to run only scenario 2 using some tag system, how can I achieve the same?

    opened by PankajNalawade 4
  • Relation to Cucumber

    Relation to Cucumber

    I got a remark and a question :)

    1. Remark: in your wiki: " Green Coffee is a library that allows you to run Cucumber test in your Android instrumentation tests. With Cucumber you write acceptance tests using Gherkin and Green Coffee executes those tests using the step definitions that you declare. " This is somehow misleading to inexperienced users. Cucumber is a tool that supports BDD. It is used to parse, run and generate reports for tests written in Gherkin exactly as your library, except more limited. So the whole thing is a bit wrong and confusing here.

    2. Question:
      I am curious what is the motivation to create this and relation to Cucumber. For quite some time(>3yrs) you can use Cucumber on Android using CucumberInstrumentation along with all other cucumber features. I also see the whole gherkin parser is actually placed in your library itself. Isn't it Cucumber-Android reinvented? Is it supposed to be more light-weight? Easy to use? Complementary? Or just inspired?

    I'd be very happy if you were willing to shed some light on this. (disclaimer: I'm not affiliated with Cucumber nor its creators;I'm just a curious dev :)

    opened by djodjoni 4
  • Kotlin Support

    Kotlin Support

    Hi,

    Is there any chance you will start to support Kotlin? Currently, I tried to use with Kotlin, however, there are several issues with it, such as Step Definition not found

    opened by look416 3
  • Sharing steps between tests

    Sharing steps between tests

    We have common steps like "Given I'm logged in" that needs to be shared between tests, what the best way to do this? I already tried extending off a CommonSteps class that extends from GreenCoffeeSteps but it's not inheriting the step definitions.

    opened by chris-gunawardena 3
  • green-coffee vs cucumber

    green-coffee vs cucumber

    I have rather a question than a remark :)

    I've used green coffee in one of my previous projects, it was awesome, it fitted well to the project needs ( app project developed with Java)

    Now I am facing a new project, a library android project, using Java and going to use kotlin also in the project, and i can not find any comparing documents between green-coffee and cucumber.

    my question maybe will not be an exact question, is green-coffee could really replace cucumber ?

    is there any recommendations or project specifications ( technical or other) that make us choose green-coffee over cucumber or the opposite ?

    I will be really happy if you could give me your opinion, over my questions , also i think its not only my question, maybe on light of your response, we could add to the wiki an objectify comparison between those tow libraries :)

    opened by mlsem 2
  • Screenshot does not contain dialogs

    Screenshot does not contain dialogs

    Hi. I need to take screenshot of failed test with displayed dialog, but unfortunatelly, takeScreenshot method does not handle dialogs. I've find library, which can handle my case (https://github.com/jraska/Falcon), but I can't pass it to GreenCoffeeConfig.

    I've written a ScreenshotProvider to add my own takeScreenshot implementation. Please look at the PR #18 , I think it can be also helpful for the other people.

    opened by klamborowski 2
  • Using grantPermission

    Using grantPermission

    I have two questions regarding the grantPermission method:

    1. Where's the best place to put the initialization? Here's one place I thought of:
      override fun beforeScenarioStarts(scenario: Scenario?, locale: Locale?) {
            super.beforeScenarioStarts(scenario, locale)
            grantPermission("android.permission.ACCESS_FINE_LOCATION")
        }
    
    1. What strings are permitted? For instance, grantPermission calls executeShellCommand which takes a Manifest-permitted String for permission, contrasted against something like GrantPermissionRule which would take something along the lines of android.Manifest.permission.ACCESS_FINE_LOCATION.
    opened by jocmp 2
  • Is it possible to pass a objects into the steps like ActivityTestRule or WireMockRule?

    Is it possible to pass a objects into the steps like ActivityTestRule or WireMockRule?

    We have steps that require different mocks and at the moment not sure how to access @Rule objects declared in the main test file. Same goes for context, is there away to access this from the steps definitions?

    opened by chris-gunawardena 2
Releases(3.6.0)
Owner
Mauricio Togneri
Mauricio Togneri
Easily scale your Android Instrumentation Tests across Firebase Test Lab with Flank.

Easily scale your Android Instrumentation Tests across Firebase Test Lab with Flank.

Nelson Osacky 220 Nov 29, 2022
3 types of Tests in Android (Unit - instrumentation - UI)

UnitTestingPractice 3 types of Tests in Android Unit instrumentation (Integration) UI Unit Testing benefits confirm code work like a charm simulate Ap

Ahmed Tawfiq 8 Mar 23, 2022
A custom instrumentation test runner for Android that generates XML reports for integration with other tools.

Android JUnit Report Test Runner Introduction The Android JUnit report test runner is a custom instrumentation test runner for Android that creates XM

Jason Sankey 148 Nov 25, 2022
A JUnit5 Platform TestEngine integrated with the official FHIR Validator to run profile and Questionnaire validation as tests.

?? FHIR Validator JUnit Engine A JUnit5 TestEngine to integrate the FHIR Validator into the JUnit5 ecosystem. Supports writing expected validation out

NAV IT 2 Feb 2, 2022
Most popular Mocking framework for unit tests written in Java

Most popular mocking framework for Java Current version is 3.x Still on Mockito 1.x? See what's new in Mockito 2! Mockito 3 does not introduce any bre

mockito 13.6k Jan 4, 2023
A program to calculate the distance traveled during the run the calories burned and the average speed Display data in more than one way using a graph

Running App Features: A program to calculate the distance traveled during the run the calories burned and the average speed Display data in more than

mostafa elmorshdi 1 Nov 21, 2022
PowerMock is a Java framework that allows you to unit test code normally regarded as untestable.

Writing unit tests can be hard and sometimes good design has to be sacrificed for the sole purpose of testability. Often testability corresponds to go

PowerMock 3.9k Jan 5, 2023
PowerMock is a Java framework that allows you to unit test code normally regarded as untestable.

Writing unit tests can be hard and sometimes good design has to be sacrificed for the sole purpose of testability. Often testability corresponds to go

PowerMock 3.9k Jan 2, 2023
Toster - Small test dsl based on adb commands that allows you to test the mobile application close to user actions

toster Small test dsl based on adb commands that allows you to test the mobile a

Alexander Kulikovskiy 31 Sep 1, 2022
kraskaska-runner: This application allows you to automatically restart specific command. Initially made for minecraft servers.

kraskaska-runner This application allows you to automatically restart specific command. Initially made for minecraft servers. Usage: Usage: kraskaska-

Kraskaska 2 Aug 30, 2022
Raccoon is a lightweight response mocking framework that can be easily integrated into the Android UI tests.

Raccoon Medium Articles Checkout these article to get more insights about this library: How to integrate this in your Android Test Why Raccoon? There

Joseph James 52 Aug 15, 2022
A simple project to help developers in writing their unit tests in Android Platform.

AndroidUnitTesting A simple project to help developers in writing their unit tests in Android Platform. This is not a multi-module project, but has th

Bruno Gabriel dos Santos 4 Nov 10, 2021
Espresso - Use Espresso to write concise, beautiful, and reliable Android UI tests

Espresso Use Espresso to write concise, beautiful, and reliable Android UI tests

Android For All 1 Jan 26, 2022
A collection of tests and easy to reuse pieces of code for bdk-jvm and bdk-android

Readme This repo is a collection of tests and easy to reuse pieces of code for bdk-jvm and bdk-android. Note that they don't aim to provide a full cov

thunderbiscuit 1 Jun 28, 2022
Using grpc-wiremock to mock responses in integrated tests of gRPC services

Utilizando grpc-wiremock para mockar respostas em testes integrados de serviços gRPC Este repositório possui um exemplo prático de como configurar e r

Tony A. Luz 2 Oct 28, 2021
Write Tests as Examples on the Method-under-test

Write Tests as Examples on the Method-under-test

Paul Methfessel 1 Apr 12, 2022
Automated tests using Rest-assured with Kotlin lang

Testes de API em Kotlin Pré-requisitos Instalar o Kotlin Ambiente Para executar os testes localmente, estou utilizando o ServeRest Link do Repo: https

Rafael Berçam 15 Dec 23, 2022
Lightweight service for creating standalone mock, written in pure Kotlin with Netty container.

MockService The lightweight service for creating a standalone mock, written in pure Kotlin with Netty container. The service allows getting config fil

null 2 Oct 28, 2021
null 866 Dec 27, 2022