CodemateLtd/Android-Cucumber-BDD-Sample

Name: Android-Cucumber-BDD-Sample

Owner: Codemate Ltd

Description: A sample project that has most of the tests and code written in a Behaviour Driven Development style, using the Cucumber framework.

Created: 2017-01-09 10:23:41.0

Updated: 2018-03-04 12:31:46.0

Pushed: 2017-10-28 22:28:51.0

Homepage: null

Size: 566

Language: Java

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Behavior-Driven Development with Cucumber

Build Status Coverage Status

Sample Video

This is a sample Android app that has BDD-style tests made using the Cucumber framework. The app acts like a library book search, allowing you to search for books by title, author or year.

Cucumber is a BDD testing framework that allows people without programming background write specifications that can be translated to unit test requirements almost automatically.

The feature file that has all functionality requirements that the application must fulfill is located here.

An example

The Springfield City Library needs a simple mobile app for searching their book collection while away from their computer. For the first version of the search feature, there's only one thing to implement:

This translates to the following Gherkin syntax, which could be even written by the customer or project lead.

booksearch.feature:

ure: Book Search
Scenario: Search books by author
  Given there's a book called "Tips for job interviews" written by "John Smith"
    And there's a book called "Bananas and their many colors" written by "James Doe"
    And there's a book called "Mama look I'm a rock star" written by "John Smith"
  When an employee searches by author "John Smith"
  Then 2 books should be found
    And Book 1 has the title "Tips for job interviews"
    And Book 2 has the title "Mama look I'm a rock star"

Simple, isn't it? This can easily be read and understood by non-programmers!

From that file, Cucumber pretty much autogenerates the Regular Expressions and Annotations needed to match the specific criterias. Then we only need to add the test logic and if we want, modify the method names.

BookSearchSteps.java (annotations and methods auto-generated):

ic class BookSearchSteps {
private Library library = new Library();
private List<Book> searchResults = new ArrayList<>();

@Given("^there's a book called \"([^\"]*)\" written by \"([^\"]*)\"$")
public void addBook(String title, String author) throws Throwable {
    Book book = new Book(title, author);
    library.addBook(book);
}

@When("^an employee searches by author \"([^\"]*)\"$")
public void searchForAuthor(String authorQuery) throws Throwable {
    searchResults = library.findBooksByAuthor(authorQuery);
}

@And("^Book (\\d+) has the title \"([^\"]*)\"$")
public void verifyBookFound(int position, String title) throws Throwable {
    int realPosition = position - 1;
    assertEquals(title, searchResults.get(realPosition).getTitle());
}

Now that we have the tests in place, we just implement the functionality to make the tests pass!

License

right 2016 Codemate Ltd

nsed under the Apache License, Version 2.0 (the "License");
may not use this file except in compliance with the License.
may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

ss required by applicable law or agreed to in writing, software
ributed under the License is distributed on an "AS IS" BASIS,
OUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
the License for the specific language governing permissions and
tations under the License.

This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.