• Stars
    star
    135
  • Rank 269,223 (Top 6 %)
  • Language
    Kotlin
  • License
    MIT License
  • Created over 6 years ago
  • Updated 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Android support for Cucumber-JVM

Build

Cucumber-Android

This project implements Android support for Cucumber-JVM. It allows running cucumber tests with Android Test Orchestrator and using sharding.

NOTE: Although minSdkVersion for 'cucumber-android' is 14 it requires Java 7 language features and minimum Android API level 19. This is done purposely to allow using cucumber in apps with lower minSdk (to avoid compile errors) but tests should be run on devices with API >= 19

Developers

Prerequisites

This is ordinary multimodule Android project

  • cucumber-android - main library
  • cukeulator - sample application with instrumented tests

Building

./gradlew assemble

Setting up the dependency

The first step is to include cucumber-android into your project, for example, as a Gradle androidTestImplementation dependency:

androidTestImplementation "io.cucumber:cucumber-android:$cucumberVersion"

Using Cucumber-Android

  1. Create a class in your test package (usually <package name from AndroidManifest>.test and add @CucumberOptions annotation to that class. This class doesn't need to have anything in it, but you can also put some codes in it if you want. The purpose of doing this is to provide cucumber options. A simple example can be found in cukeulator. Or a more complicated example here:
@CucumberOptions(glue = "com.mytest.steps", format = {"junit:/data/data/com.mytest/JUnitReport.xml", "json:/data/data/com.mytest/JSONReport.json"}, tags = { "~@wip" }, features = "features")
public class MyTests 
{
}

glue is the path to step definitions, format is the path for report outputs, tags is the tags you want cucumber-android to run or not run, features is the path to the feature files.
You can also use command line to provide these options to cucumber-android. Here is the detailed documentation on how to use command line to provide these options: Command Line Options for Cucumber Android

  1. Write your .feature files under your test project's assets/ folder. If you specify features = "features" like the example above then it's assets/features.

  2. Write your step definitions under the package name specified in glue. For example, if you specified glue = "com.mytest.steps", then create a new package under your src folder named "com.mytest.steps" and put your step definitions under it. Note that all subpackages will also be included, so you can also put in "com.mytest.steps.mycomponent".

  3. Set instrumentation runner to io.cucumber.android.runner.CucumberAndroidJUnitRunner or class that extends it

android.defaultConfig.testInstrumentationRunner "io.cucumber.android.runner.CucumberAndroidJUnitRunner"

Debugging

Please read the Android documentation on debugging.

Examples

Currently there is one example in subproject cukeulator

To create a virtual device and start an Android emulator:

$ANDROID_HOME/tools/android avd

Junit rules support

Experimental support for Junit rules was added in version 4.9.0. Cucumber works differently than junit - you cannot just add rule to some steps class because during scenario execution many such steps classes can be instantiated. Cucumber has its own Before/After mechanism. If you have just 1 steps class then this could work If you have many steps classes then it is better to separate rule and @Before/@After hooks
from steps classes

To let Cucumber discover that particular class has rules add

@WithJunitRule
class ClassWithRules {
    ...
}

Jetpack Compose rule

@WithJunitRule
class ComposeRuleHolder {

    @get:Rule
    val composeRule = createEmptyComposeRule()
}

then inject this object in steps, e.g. (can be also inject as lateinit var field (depending on injection framework used)

class KotlinSteps(val composeRuleHolder: ComposeRuleHolder, val scenarioHolder: ActivityScenarioHolder):SemanticsNodeInteractionsProvider by composeRuleHolder.composeRule {

    ...
    
    @Then("^\"([^\"]*)\" text is presented$")
    fun textIsPresented(arg0: String) {
        onNodeWithText(arg0).assertIsDisplayed()
    }
}

Hilt

There are 2 solutions for using Hilt with Cucumber:

1. HiltObjectFactory

Add dependency:

androidTestImplementation "io.cucumber:cucumber-android-hilt:$cucumberVersion"

Don't use any other dependency with ObjectFactory like cucumber-picocontainer

HiltObjectFactory will be automatically used as ObjectFactory.

To inject object managed by Hilt into steps or hook or any other class managed by Cucumber:

@HiltAndroidTest
class KotlinSteps(
    val composeRuleHolder: ComposeRuleHolder,
    val scenarioHolder: ActivityScenarioHolder
):SemanticsNodeInteractionsProvider by composeRuleHolder.composeRule {

    @Inject
    lateinit var greetingService:GreetingService

    @Then("I should see {string} on the display")
    fun I_should_see_s_on_the_display(s: String?) {
       Espresso.onView(withId(R.id.txt_calc_display)).check(ViewAssertions.matches(ViewMatchers.withText(s)))
    }

}

Such class:

  • must have @HiltAndroidTest annotation to let Hilt generate injecting code
  • can have Cucumber managed objects in constructor
  • can have Hilt managed objects injected only using field injection - cannot have them injected in constructor
2. @WithJunitRule

Hilt requires to have rule in actual test class (which for cucumber is impossible because there is no such class). To workaround that:

See https://developer.android.com/training/dependency-injection/hilt-testing#multiple-testrules how to use hilt with other rules (like compose rule)

@WithJunitRule(useAsTestClassInDescription = true)
@HiltAndroidTest
class HiltRuleHolder {

    @Rule(order = 0) 
    @JvmField
    val hiltRule = HiltAndroidRule(this)

   //if you need it to be injected   
    @Inject
    lateinit var greetingService: GreetingService

    @Before
    fun init() {
        //if you have anything to inject here and/or used elsewhere in tests    
        hiltRule.inject()
    }

}

then you can inject such class to steps class using Cucumber dependency injector (like picocontainer)

Running scenarios from IDE

There is third-party plugin (not related with Cucumber organisation and this repository) which allows running scenarios directly from Android Studio or Intellij

Cucumber for Kotlin and Android

More Repositories

1

cucumber-ruby

Cucumber for Ruby. It's amazing!
Ruby
5,178
star
2

cucumber-js

Cucumber for JavaScript
TypeScript
5,053
star
3

common

A home for issues that are common to multiple cucumber repositories
3,363
star
4

cucumber-jvm

Cucumber for the JVM
Java
2,702
star
5

godog

Cucumber for golang
Go
2,307
star
6

cucumber-rails

Rails Generators for Cucumber with special support for Capybara and DatabaseCleaner
Ruby
1,021
star
7

aruba

Test command-line applications with Cucumber-Ruby, RSpec or Minitest.
Ruby
948
star
8

cucumber-java-skeleton

This is the simplest possible setup for Cucumber-JVM using Java.
Java
461
star
9

cucumber-cpp

Support for writing Cucumber step definitions in C++
C++
308
star
10

cucumber-eclipse

Eclipse plugin for Cucumber
Java
192
star
11

gherkin

A parser and compiler for the Gherkin language.
C
182
star
12

cucumber-expressions

Human friendly alternative to Regular Expressions
Java
155
star
13

docs

Cucumber user documentation
CSS
151
star
14

cucumber-electron

Run cucumber.js in electron
JavaScript
118
star
15

gherkin-go

[READ-ONLY] Gherkin for Go - subtree of https://github.com/cucumber/gherkin -- moved to https://github.com/cucumber/gherkin
Go
84
star
16

gherkin-javascript

[READ-ONLY] Gherkin for JavaScript - subtree of monorepo https://github.com/cucumber/cucumber -- moved to https://github.com/cucumber/gherkin
TypeScript
79
star
17

gherkin-python

[READ-ONLY] Gherkin for Python - subtree of monorepo https://github.com/cucumber/cucumber -- moved to https://github.com/cucumber/gherkin
Python
76
star
18

vscode

Official Visual Studio Code Extension for Cucumber
TypeScript
66
star
19

screenplay.js

Library to ease implementation of the Screenplay pattern with CucumberJS
TypeScript
56
star
20

gherkin-java

[READ-ONLY] Gherkin for Java - subtree of monorepo https://github.com/cucumber/cucumber -- moved to https://github.com/cucumber/gherkin
Java
49
star
21

cucumber-jvm-scala

Cucumber Scala
Scala
48
star
22

gherkin-dotnet

[READ-ONLY] Gherkin for Dotnet - subtree of monorepo https://github.com/cucumber/cucumber Gherkin parser/compiler for .NET
C#
46
star
23

language-server

Cucumber Language Server
TypeScript
36
star
24

cucumber-ruby-core

Core library for the Ruby flavour of Cucumber
Ruby
35
star
25

react-components

React components for Cucumber
TypeScript
34
star
26

cucumber-lua

A cucumber wire protocol implementation for Lua step definitions
Lua
29
star
27

cucumber.ml

Cucumber for OCaml
OCaml
27
star
28

cucumber-js-examples

Examples of using Cucumber-JS
Makefile
25
star
29

blockly

Gherkin Editor based on Blockly
TypeScript
24
star
30

cucumber-jvm-groovy

Cucumber Groovy
Java
23
star
31

microdata

Extract WHATWG microdata from a DOM
TypeScript
22
star
32

json-formatter

Provides a language-agnostic command-line tool to convert cucumber messages into a JSON document.
Go
21
star
33

messages

A message protocol for representing results and other information from Cucumber
C#
19
star
34

language-service

Cucumber Language Service
TypeScript
18
star
35

cucumber-js-pretty-formatter

Cucumber.js pretty formatter
TypeScript
17
star
36

monaco

Configure Monaco editor to use cucumber-language-service
TypeScript
16
star
37

html-formatter

HTML formatter for reporting Cucumber results
Java
14
star
38

gherkin-utils

API for working with Gherkin documents
TypeScript
12
star
39

ci-environment

Detect CI Environment from environment variables
Java
10
star
40

gherkin-c

[READ-ONLY] Gherkin for C - subtree of monorepo https://github.com/cucumber/cucumber -- moved to https://github.com/cucumber/gherkin
C
10
star
41

tag-expressions

Cucumber tag expression parser
Python
9
star
42

screenplay.js.examples

Examples using @cucumber/screenplay
TypeScript
7
star
43

cucumber-eclipse-update-site-snapshot

Cucumber Eclipse Update Site Snapshots
CSS
7
star
44

gherkin-objective-c

[READ-ONLY] Gherkin for Objective C - subtree of monorepo https://github.com/cucumber/cucumber -- moved to https://github.com/cucumber/gherkin
Objective-C
7
star
45

gherkin-ruby

[READ-ONLY] Gherkin for Ruby - subtree of monorepo https://github.com/cucumber/cucumber -- moved to https://github.com/cucumber/gherkin
Ruby
7
star
46

cucumber-ruby-wire

Wire protocol plugin for Cucumber
Gherkin
7
star
47

cucumber-json-converter

Parse Cucumber JSON from most Cucumber implementations and versions
TypeScript
6
star
48

polyglot-release

Make polyglot releases with a single command
Shell
5
star
49

todo-react-typescript-subsecond

Tiny Todo app in React and TypeScript demonstrating sub-second test feedback
TypeScript
4
star
50

action-retire-inactive-contributors

Retire inactive contributors from one team to another
TypeScript
4
star
51

cucumber-json-schema

JSON Schemas for Cucumber JSON output
JavaScript
4
star
52

messages-go

[READ ONLY] Cucumber Messages for Go - subtree of monorepo https://github.com/cucumber/messages -- moved to https://github.com/cucumber/messages
Go
3
star
53

gherkin-streams

Stream utilities to read Gherkin parser output.
TypeScript
3
star
54

try-cucumber-expressions

Try Cucumber Expressions in your browser
TypeScript
3
star
55

cucumber-eclipse-update-site

Cucumber Eclipse Update Site
3
star
56

github-settings

Pulumi scripts to automatically configure our GitHub org/repo settings
TypeScript
2
star
57

gherkin-perl

[READ-ONLY] Gherkin for Perl - subtree of monorepo https://github.com/cucumber/cucumber -- moved to https://github.com/cucumber/gherkin
Perl
2
star
58

gherkin-php

[READ ONLY] Cucumber Gherkin for PHP - subtree of https://github.com/cucumber/gherkin
PHP
2
star
59

junit-xml-formatter

JUnit XML formatter for reporting Cucumber results
Java
2
star
60

oselvar-github-metrics

Oselvar GitHub Metrics for the Cucumber Organisation
Shell
2
star
61

build

Docker image used to build the Cucumber Project
Shell
2
star
62

fake-cucumber

Tool to generate test data for cucumber
TypeScript
2
star
63

messages-javascript

[READ ONLY] Cucumber Messages for JavaScript (Protocol Buffers) - subtree of monorepo https://github.com/cucumber/cucumber -- moved to https://github.com/cucumber/messages
TypeScript
2
star
64

commitbit

Microservice that hands out commit bit to everyone who gets a pull request merged
JavaScript
2
star
65

query

A query API for https://github.com/cucumber/messages
Java
2
star
66

aruba-getting-started

Getting started with aruba
Ruby
2
star
67

action-publish-cpan

GitHub Action to publish a Perl module to CPAN
Perl
1
star
68

community-calendar

Public calendar for community calls and events
1
star
69

action-changelog

GitHub Action for changelog tool
Shell
1
star
70

release-announcement-banner

For blog posts where we announce a new version of a Cucumber tool
JavaScript
1
star
71

split-java

A Cucumber plugin to toggle Split features from Cucumber scenarios
Java
1
star
72

cucumber-js-package-upgrade

package to point users to the new @cucumber/cucumber
JavaScript
1
star
73

messages-java

[READ ONLY] Cucumber Messages for Java (Protocol Buffers) - subtree of monorepo https://github.com/cucumber/cucumber
Java
1
star
74

action-publish-subrepo-test-monorepo-a-subfolder

target for tests for https://github.com/cucumber/action-publish-subrepo
1
star
75

cucumber-parent

Parent `pom.xml` for all Cucumber Java modules
1
star
76

action-publish-rubygem

GitHub Action to publish a Ruby Gem
Ruby
1
star
77

compatibility-kit

Platform-agnostic set of acceptance tests for validating cucumber implementations
TypeScript
1
star
78

action-publish-subrepo-test-monorepo

Test repo for testing the action-publish-subrepo GitHub Action
1
star
79

messages-ruby

[READ ONLY] Cucumber Messages for Ruby (Protocol Buffers) - subtree of monorepo https://github.com/cucumber/cucumber -- moved to https://github.com/cucumber/messages
Ruby
1
star
80

renovate-config

Shareable Config Presets for Renovate in the Cucumber org
1
star
81

action-publish-mvn

GitHub Action to publish Maven artefacts
Java
1
star
82

message-streams

Stream utilities to read and write Cucumber Message objects to/from streams.
TypeScript
1
star
83

action-publish-npm

GitHub Action to publish an NPM module
1
star
84

messages-dotnet

[READ ONLY] Cucumber Messages for .NET (Protocol Buffers) - subtree of monorepo https://github.com/cucumber/cucumber -- moved to https://github.com/cucumber/messages
Makefile
1
star
85

.github

๐Ÿ‘ฉโ€โš•๏ธ Default community health files for the Cucumber organisation on GitHub.
Shell
1
star