mirror of
https://github.com/hmalik144/Android-Cucumber-BDD-Sample.git
synced 2026-01-31 02:41:37 +00:00
Added a license and removed the default file template boilerplate.
This commit is contained in:
15
README.md
15
README.md
@@ -1,14 +1,12 @@
|
||||
# Behavior-Driven Development with Cucumber
|
||||
|
||||
This is a sample Android app that has tests mostly written using the Cucumber framework. The app acts like a library book search, allowing you to search for books by title, author or year. **The test coverage is 97%**.
|
||||
This is a sample Android app that has tests mostly written using the Cucumber framework. The app acts like a library book search, allowing you to search for books by title, author or year.
|
||||
|
||||
[Cucumber](https://cucumber.io/) is a BDD testing framework that allows people without programming background write specifications **that can be translated to unit tests almost automatically**.
|
||||
|
||||
Writing tests turns more fun and it's no more a pain in the ass to write them first. It's also easier to specify the requirements.
|
||||
[Cucumber](https://cucumber.io/) is a BDD testing framework that allows people without programming background write specifications **that can be translated to unit test requirements almost automatically**.
|
||||
|
||||
## An example
|
||||
|
||||
The Oulu City Library has an application for book management.
|
||||
The Springfield City Library has an application for book management.
|
||||
|
||||
The application is working fine, but they don't have a search feature. For the first version of the search feature, there's only one thing to implement:
|
||||
|
||||
@@ -20,14 +18,13 @@ This translates to the following **Gherkin** syntax, which could be even written
|
||||
|
||||
```gherkin
|
||||
Feature: Book Search
|
||||
|
||||
Scenario: Search books by author
|
||||
Given there's a book called "Tips for horrible hangovers" written by "John Smith"
|
||||
And there's a book called "Bananas and their many colors" written by "James Brown"
|
||||
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 horrible hangovers"
|
||||
And Book 1 has the title "Tips for job interviews"
|
||||
And Book 2 has the title "Mama look I'm a rock star"
|
||||
```
|
||||
|
||||
|
||||
@@ -2,9 +2,6 @@ package com.codemate.booklibrary.data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* Created by ironman on 01/09/16.
|
||||
*/
|
||||
public class Book {
|
||||
private final String title;
|
||||
private final String author;
|
||||
|
||||
@@ -4,9 +4,6 @@ import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by ironman on 01/09/16.
|
||||
*/
|
||||
public class Library {
|
||||
private List<Book> inventory = new ArrayList<>();
|
||||
|
||||
|
||||
@@ -5,9 +5,6 @@ import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by ironman on 02/09/16.
|
||||
*/
|
||||
public class RandomBookGenerator {
|
||||
private static final String[] SUBJECTS = {
|
||||
"Chicken", "Pig", "Hippo", "Dinosaur", "Giraffe", "Orangutan",
|
||||
|
||||
@@ -2,9 +2,6 @@ package com.codemate.booklibrary.data;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* Created by ironman on 02/09/16.
|
||||
*/
|
||||
public class RandomUtils {
|
||||
private RandomUtils() {}
|
||||
|
||||
|
||||
@@ -14,9 +14,6 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* Created by ironman on 02/09/16.
|
||||
*/
|
||||
public class BookAdapter extends RecyclerView.Adapter<BookAdapter.ViewHolder> {
|
||||
private final SimpleDateFormat dateFormat;
|
||||
private List<Book> items = new ArrayList<>();
|
||||
|
||||
@@ -8,9 +8,6 @@ import com.codemate.booklibrary.data.RandomBookGenerator;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by ironman on 02/09/16.
|
||||
*/
|
||||
public class MainPresenter {
|
||||
private final MainView mainView;
|
||||
private final Library library;
|
||||
|
||||
@@ -4,9 +4,6 @@ import com.codemate.booklibrary.data.Book;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by ironman on 02/09/16.
|
||||
*/
|
||||
public interface MainView {
|
||||
void showBooks(List<Book> books);
|
||||
}
|
||||
|
||||
@@ -7,9 +7,6 @@ import org.junit.runner.RunWith;
|
||||
import cucumber.api.CucumberOptions;
|
||||
import cucumber.api.junit.Cucumber;
|
||||
|
||||
/**
|
||||
* Created by ironman on 01/09/16.
|
||||
*/
|
||||
@RunWith(Cucumber.class)
|
||||
@CucumberOptions(features = "src/test/resources")
|
||||
public class CucumberTests extends TestCase {
|
||||
|
||||
@@ -5,9 +5,6 @@ import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by ironman on 02/09/16.
|
||||
*/
|
||||
public class LibraryTest {
|
||||
@Test
|
||||
public void addMultipleBooks_PersistsThemInLibrary() {
|
||||
|
||||
@@ -8,9 +8,6 @@ import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
/**
|
||||
* Created by ironman on 02/09/16.
|
||||
*/
|
||||
public class RandomBookGeneratorTest {
|
||||
@Test
|
||||
public void generatingRandomBooks_ReturnsNonEmptyBookList() {
|
||||
|
||||
@@ -25,9 +25,6 @@ import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
/**
|
||||
* Created by ironman on 01/09/16.
|
||||
*/
|
||||
public class BookSearchSteps {
|
||||
private Library library = new Library();
|
||||
private List<Book> results = new ArrayList<>();
|
||||
@@ -75,7 +72,7 @@ public class BookSearchSteps {
|
||||
@And("^Book (\\d+) should have the title \"([^\"]*)\"$")
|
||||
public void verifyBookAtPosition(int position, String title) throws Throwable {
|
||||
int realPosition = position - 1;
|
||||
Assert.assertEquals(title, results.get(realPosition).getTitle());
|
||||
assertEquals(title, results.get(realPosition).getTitle());
|
||||
}
|
||||
|
||||
@And("^Books should be (.+)$")
|
||||
|
||||
@@ -18,9 +18,6 @@ import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* Created by ironman on 02/09/16.
|
||||
*/
|
||||
public class MainPresenterTest {
|
||||
private static final List<Book> DUMMY_BOOKS = Arrays.asList(
|
||||
new Book("Sample book one", "John Doe", Date.valueOf("2000-10-25")),
|
||||
|
||||
Reference in New Issue
Block a user