background preloader

BDD

Facebook Twitter

Enabling Cucumber Support in Project. In this section: Prerequisite.

Enabling Cucumber Support in Project

Testing from the Outside-In. A few months ago my colleague Josh Steiner wrote a comprehensive post on How We Test Rails Applications, detailing the different types tests we write and the various technologies that go with them.

Testing from the Outside-In

In this follow up, we will take a closer look at thoughtbot’s testing workflow. We use a process known as “Outside-in testing”, driving our development from high-level tests and working our way down to lower-level concerns. Say we are working on an e-commerce site and want to implement the following story: As a guest, I can add items to my shopping cart so that I can keep on shopping Before we start thinking about models, controllers, or other architectural concerns we write a high-level RSpec feature test that describes the behavior from the user’s perspective. Depending on how much of the application is implemented, this test could break in multiple places. Resources :items, only: [:index] def index @items = Item.search(params[:search_query]) end def self.search(term) where(name: term) end. Behavior Driven Development. Unit Testing with Stubs and Mocks.

I was on site with some clients the other day, and they asked me about unit testing and mock objects.

Unit Testing with Stubs and Mocks

I decided to write up some of the discussion we had as a tutorial on creating dependencies (collaborators) for unit testing. We discuss two options, stubbing and mock objects and give some simple examples that illustrate the usage, and the advantages and disadvantages of both approaches. It is common in unit tests to mock or stub collaborators of the class under test so that the test is independent of the implementation of the collaborators. Cucumber-Jvm with Cucumber-Java + Cucumber-JUnit Example. In this post I will show you how to add Cucumber-Jvm to your project, how to write a scenarios and step definitions using JUnit 4, and of course how to execute those scenarios, all that using the Java language.

Cucumber-Jvm with Cucumber-Java + Cucumber-JUnit Example

No more Ruby dependency, :). I have created a simple Banking application using Eclipse IDE to demonstrate writing and executing scenarios. Well, the application hasn’t been built, at this point I have just a blank Maven project. I’ll be employing Behaviour Driven Development (BDD) to write the tests and then the implementation, using outside-in development to ensure that the only code I write is code that is needed to meet the acceptance criteria. After creating a blank Maven project, you need to add the following dependencies to your project’s pom.xml file: A standard Maven project directory structure will have a source folder src/test/resources, this is the directory where you should create your .feature files. Create a file called deposit.feature in src/test/resources.

When TDD doesn't work. Over the years many people have complained about the so-called "religiosity" of some of the proponents of Test Driven Development.

When TDD doesn't work.

The recent brouhaha over TDD has, once again, brought these complaints to the fore. So I thought it would be a good idea to talk about when TDD does not work. I have often compared TDD to double-entry bookkeeping. The act of stating every bit of logic twice, once in a test, and once in the production code, is very similar to the accounting practice of entering every transaction twice, once on the asset side, and once on the liability side. The running of the tests is very similar to the creation of the balance sheet. So stating that there are places that TDD doesn't work may seem like stating that there are places where double entry bookkeeping doesn't work.

Tutorials and Related Blog Posts · cucumber/cucumber Wiki. Thomas Sundberg. Before I can try to motivate why you should use a tool, let me define what it is and what it does.

Thomas Sundberg

What is cucumber? Cucumber is a tool for collaboration and testing. It is used to create examples of behaviour that are executable. Creating examples in a collaborative way emphasize close cooperation between business analysts, testers and developers. The examples they come up with can be used as acceptance tests for the system being developed. Goal Our goal is to create a common understanding of the problem and therefore simplify the communication between all parties involved. Why use Cucumber?

The main reason for using Cucumber is that it is easy to express requirements using concrete examples that are hard to interpret in more than one way. We are able to replace vaguely defined problems with well defined, concrete examples and get acceptance criteria that can be automated in the process. Why not write source code? Being concrete and precise is the same thing as writing source code. Feature Introduction · cucumber/cucumber Wiki. Every .feature file conventionally consists of a single feature.

Feature Introduction · cucumber/cucumber Wiki

A line starting with the keyword Feature followed by free indented text starts a feature. A feature usually contains a list of scenarios. You can write whatever you want up until the first scenario, which starts with the word Scenario (or localized equivalent; Gherkin is localized for dozens of languages) on a new line. You can use tagging to group features and scenarios together independent of your file and directory structure. Every scenario consists of a list of steps, which must start with one of the keywords Given, When, Then, But or And. Step Definitions · cucumber/cucumber Wiki. Step definitions are defined in ruby files under features/step_definitions/*_steps.rb.

Step Definitions · cucumber/cucumber Wiki

Here is a simple example: Given /^I have (\d+) cucumbers in my belly$/ do |cukes| # Some Ruby code hereend. Gojko Adzic - BDD: Busting the myths.