All Projects → andrewjc → kheera-testrunner-android

andrewjc / kheera-testrunner-android

Licence: Apache-2.0 license
BDD Framework for Android

Programming Languages

java
68154 projects - #9 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to kheera-testrunner-android

Karate
Test Automation Made Simple
Stars: ✭ 5,497 (+30438.89%)
Mutual labels:  bdd, gherkin, testing-tools, testing-framework
bat
Gherkin based DSL for testing HTTP APIs via Cucumber.JS
Stars: ✭ 30 (+66.67%)
Mutual labels:  bdd, gherkin, testing-tools, bdd-framework
karate-runner
VSCode Extension for Karate
Stars: ✭ 23 (+27.78%)
Mutual labels:  bdd, gherkin, testing-tools, testing-framework
Awesome-Cucumber
A collection of awesome Cucumber and Gherkin-related resources
Stars: ✭ 33 (+83.33%)
Mutual labels:  bdd, gherkin, bdd-framework
hitchstory
Type-safe, StrictYAML based BDD framework for python.
Stars: ✭ 24 (+33.33%)
Mutual labels:  bdd, bdd-framework, testing-framework
karate
Test Automation Made Simple
Stars: ✭ 6,384 (+35366.67%)
Mutual labels:  bdd, testing-tools, testing-framework
behave-restful
BDD Framework to Test REST Services and APIs
Stars: ✭ 47 (+161.11%)
Mutual labels:  bdd, gherkin, testing-tools
Godog
Cucumber for golang
Stars: ✭ 1,287 (+7050%)
Mutual labels:  bdd, integration-testing, gherkin
api-test
🌿 A simple bash script to test JSON API from terminal in a structured and organized way.
Stars: ✭ 53 (+194.44%)
Mutual labels:  integration-testing, testing-tools, testing-framework
kekiri
A .NET framework that supports writing low-ceremony BDD tests using Gherkin language
Stars: ✭ 19 (+5.56%)
Mutual labels:  bdd, bdd-framework
featurebook
A command line tool (and Node.js library) for generating beautiful system specifications from Gherkin source files.
Stars: ✭ 40 (+122.22%)
Mutual labels:  bdd, gherkin
bdd
JUnit 5 based BDD library to create and run stories and behaviors a.k.a BDD specification tests
Stars: ✭ 25 (+38.89%)
Mutual labels:  bdd, bdd-framework
mocha-cakes-2
A BDD plugin for Mocha testing framework
Stars: ✭ 44 (+144.44%)
Mutual labels:  bdd, gherkin
pysys-test
PySys System Test Framework
Stars: ✭ 14 (-22.22%)
Mutual labels:  integration-testing, testing-framework
cucumber-performance
A performance testing framework for cucumber
Stars: ✭ 28 (+55.56%)
Mutual labels:  bdd, gherkin
AutoMeter-API
AutoMeter-API是一款针对分布式服务,微服务API功能和性能一体的自动化测试平台,一站式解决应用,服务,API,环境管理,用例,条件,测试场景,计划,测试报告,功能/性能测试兼容支持的一体化工作平台
Stars: ✭ 105 (+483.33%)
Mutual labels:  testing-tools, testing-framework
cl-spec
BDD for Common Lisp
Stars: ✭ 18 (+0%)
Mutual labels:  testing-tools, bdd-framework
nim-contra
Lightweight Self-Documenting Design by Contract Programming and Security Hardened mode.
Stars: ✭ 46 (+155.56%)
Mutual labels:  testing-tools, testing-framework
cucumber-jvm-examples
Cucumber-jvm 5.0.0 examples with Maven
Stars: ✭ 20 (+11.11%)
Mutual labels:  bdd, gherkin
eaf-linter
🤪 A linter, prettier, and test suite that does everything as-simple-as-possible.
Stars: ✭ 17 (-5.56%)
Mutual labels:  testing-tools, testing-framework

Build Status

Kheera - BDD Test Framework for Android

Kheera is a BDD Test Framework, especially design for Android application development workflows. It's designed to be fast, small and completely compatible with Android Test Kit, Espresso 3, UIAutomator etc.

Features

Android Studio Integration

AndroidX Support: Supports the very latest AndroidX + Jetifier libraries

Android Test Support Library: Builds on top of the newest Android Test Support Library and AndroidJUnitRunner. Kheera tests will run alongside existing Instrumentation, Espresso or JUnit based tests in your solution. You can gradually rewrite tests in BDD as you go.

Fast Execution Engine: Designed specifically for resource constrained Android devices, Kheera is optimised for test execution speed and memory usage.

SDK Filtering: Restrict certain tests to specific devices running a given android sdk. For example if you have a scenario in your feature file that you only want to run on connected devices where the Android SDK version is between 16 and 28 you can filter using the minSdkVersion and maxSdkVersion tag. An example is shown in the sample app.

Regex Filtering: Restrict which tests run in a session by specifying a regex.

Tag Filtering: Run only specific tests with a given tag, or create subsets of tests by introducing multiple tags.

Scoped Test Steps: Kheera Step Definition files are bound 1-1 to a single feature file. This makes maintaining projects with large number of features much easier. Steps are contextual to the feature they exist in, and scoped step definitions resolve issues when large number of developers are working on a single codebase.

Externalised Test Data: Allows the test data to be removed from feature files, and replaced with variables. The test data can then be provided by a 'profile'. This allows for different test data to be used during testing depending on environment. An example of this is shown in the sample app.

Getting Started

To start using Kheera BDD Test Framework in your Android project, follow these steps:

Step 1. Add JitPack.io to your app's repositories:

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

Step 2. Add the dependency

dependencies {
   androidTestImplementation 'com.github.andrewjc:kheera-testrunner-android:1.1.0'
}
  • Enable the test runner in your build.gradle file by populating the android.defaultConfig.testInstrumentationRunner property:
android {
   defaultConfig {
       ...
       testInstrumentationRunner "com.kheera.KheeraRunner"
       testApplicationId "com.[yourapp].test"
   }
}
  • You can now run Kheera BDD based tests. The test runner will run bdd tests along with any existing instrumentation tests, unit tests etc.
$ ./gradlew clean assemble connectedAndroidTest

It is highly recommended that you install the Android Studio plugin. The plugin provides autocomplete, code generation and more. It can be found in the misc directory.

Check out the sample app found here Sample

Feature Files

In the Kheera BDD framework, feature files are where you start development of a feature. By creating a new feature file, and populating it with Scenarios in Gherkin format. A single feature file will typically contain many scenarios, and would describe both success and failure criteria.

./app/src/androidTest/assets/features/Gallery.feature

Feature: New Gallery
This file contains scenarios for the new image gallery

Scenario: All my images should appear in the gallery as thumbnails
    Given I have many photos available
    When I am on the gallery page
    Then I will see my photos as thumbnails

Some general hints for writing feature files:

  • Do not drive the UI from the feature file. It can be tempting to create generic steps in the form of a DSL. In practice this just results in your scenarios mirroring the implementation in another language. If you refactor code, or redesign screens you should not need to change the feature file at all.
  • Scenario steps should describe the WHAT not the HOW. Do not specify how the UI looks. Instead specify what it is supposed to achieve or solve.
  • Write scenarios from the perspective of an end user. End users don't care if their screen is implemented with a LinearLayout or a RecyclerView.
  • Don't specify implementation details in the feature file. That's what the step definitions are for.

Step Definitions

If a feature file is where the WHAT of a requirement gets described, then the HOW is described in the step definition.

./app/src/androidTest/java/GalleryStepDefinition.java

@TestModule(featureFile = "gallery.feature")
public class GalleryStepDefinition implements StepDefinition {
   ...
}

In the code above, we create a new class that implements the StepDefinition interface. The way that Kheera knows to link this class with the feature file is with the @TestModule annotation.

Inside our new class, we then create step definition methods and annotate them with a regular expression that will match a single line from our feature file:

@TestStep("^I have many photos available$")
public void iHaveManyPhotosAvailable() throws Throwable {
    mock(photoProvider).when(getPhotoCount).doReturn(100);
}

While steps can be simple one line statements with no arguments, Kheera supports full arguments, data tables and external variables.

For example, we can have a step definition that takes an argument:

Scenario Outline: Different numbers of photos display correctly
    Given I have "<howManyPhotos>" photos available
    When I am on the gallery page
    Then I will see "<howManyPhotos"> thumbnails displayed

    Examples:
    | howManyPhotos |
    | 0             |
    | 10            |
    | 20            |

And then define a step definition that takes howManyPhotos as an argument:

@TestStep("^I have \"([^\"]*)\" photos available$")
public void iHavePhotosAvailable(int howManyPhotos) throws Throwable {
    mock(photoProvider).when(getPhotoCount).doReturn(howManyPhotos);
}

There are many more ways to write feature files, and step definitions. Be sure to check out the samples in the app for more information.

Tips and Tricks

SDK Filtering

You can specify to the test runner that a given scenario should only be run on specific SDK versions by using the minSdkVersion and maxSdkVersion attribute on the @Filter tag:

@filter(minSdkVersion=25)
Scenario: This will only run on API above 25
   Given I am on a newer android device
   ...

Or, we can combine 2 filters to run between 2 api levels:

@filter(minSdkVersion=14)
@filter(minSdkVersion=18)
Scenario: This will only run on API levels between 14 and 18
   Given I am on an older android device
   ...

Comments in feature files

The gherkin language doesn't have support for comments, so Kheera adds a special tag for commenting scenarios. It gets ignored at runtime.

@note(This is a comment line. It is ignored by the testrunner. The scenario will still run.)
Scenario: This scenario needed a comment to explain something
   Given I am rather confusing
   ...

Disable a test

If you wish to switch off a test, you can annotate it with @ignore or @disable:

@ignore
Scenario: This test is broken and should not run
   Given I wrote a flakey test
   ...

Run a specific scenario

Specify the scenario to run in testsetup.json:

**src/androidTest/assets/config/default/testsetup.json**

FilterType: "scenario"
FilterBy: "As a user i want to log in successfully"

Run all scenarios by regex match

Specify the regex to match against in testsetup.json

FilterType: "scenario"
FilterBy: "/As a user i want to/"

Run all scenarios with a given tag

Specify the tag to match against in testsetup.json

FilterType: "tag"
FilterBy: "Gallery"

Run all scenarios with a tag matching a regex

FilterType: "tag"
FilterBy: "/gallery/"

Note: This will match all tags containing 'gallery', eg 'Gallery', 'Upload to Gallery', 'Register for Gallery'.

Run just a given feature file

FilterType: 'file'
FilterBy: 'gallery.feature'

Externalising test data

It is good practice not to hard code test data into your feature file, but instead keep the test data in a seperate file, and reference it in the feature file with a variable.

The sample app has a reference for this, but here are the basic steps:

  • Specify a testdata.json file in your default/testsetup.json file:
{
   ...
   "TestData":"testdata.json"
   ...
}
  • Populate the testdata.json file. The structure of this file can be anything, as long as it's valid json:
{
   "test": {
      "account1": {
         "username":"user@domain"
         "password":"mypassword"
      }
   }
}
  • Reference the test data in your feature files:
Scenario: Test successful login to gallery
   Given I am on the signin page
   When I sign in with email "$(test.account1.username)"
   And I sign in with password "$(test.account1.password)"
   Then I will see the gallery

Or, you can use the variables in the example section of a scenario:

Scenario: Test successful login to gallery
   Given I am on the signin page
   When I sign in with "<email>" and "<password>"
   Then I will see the gallery
   Examples:
   | email                     | password                  |
   | $(test.account1.username) | $(test.account1.password) |
   | $(test.account2.username) | $(test.account2.password) |

Use Kheera with Spoon

To generate screenshots for use with Spoon, you will need to enable screenshots in your testsetup.json file:

{
   ...
   "Screenshot": true,
   ...
}

Use Kheera with Jacoco

To generate jacoco coverage, you will need to enable coverage reports in your testsetup.json file:

{
   ...
   "CoverageReport": true
   ...
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].