Skip to content

How it works

Mauricio Togneri edited this page Sep 24, 2016 · 8 revisions

In essence, Green Coffee is no more than a Gherkin test runner that you can use for your Android instrumentation tests. To understand this better, let's see the main components involved in a test execution:

Feature

Features are written using the Gherkin language. Each feature consists of one or more scenarios that describe different situations in order to test that feature. Each scenario consists of steps that will simulate user interactions with the UI.

Test definition

A test definition is a class that extends from GreenCoffeeTest and declares the Activity, the feature and the step definitions that will be used during the test. More information here.

Step definitions

The step definitions consist of set of classes that define all methods that will be used to match the steps in the scenarios involved in the test. More information here.

Green Coffee is just the glue that interconnects these three components. This is how it works:

  1. When we launch a instrumentation test, Green Coffee will read the feature declared in the test class, parse it and create the list of scenarios that will be used to run the tests
  2. For each scenario declared in the feature, the Android platform will automatically create an instance of the Activity that we declared in the test class and run a single test
  3. For each test executed, Green Coffee will automatically match each step in the corresponding scenario with the step definitions declared in the test class
  4. When a step in a scenario matches a method in the step definitions, Green Coffee will invoke that method with the corresponding parameters
  5. Each method invoked will either interact with the UI simulating a user interaction or verify that certain conditions are fulfilled

Next chapter: Test definition