background preloader

Introducing BDD

Introducing BDD
History: This article first appeared in Better Software magazine in March 2006. It has been translated into Japanese by Yukei Wachi, Korean by HongJoo Lee, Italian by Arialdo Martini and French by Philippe Poumaroux and most recently into Spanish by Oscar Zárate, Turkish by Selim Öber and Russian. I had a problem. The deeper I got into TDD, the more I felt that my own journey had been less of a wax-on, wax-off process of gradual mastery than a series of blind alleys. My response is behaviour-driven development (BDD). Test method names should be sentences My first “Aha!” renders something like this: The word “test” is stripped from both the class name and the method names, and the camel-case method name is converted into regular text. Developers discovered it could do at least some of their documentation for them, so they started to write test methods that were real sentences. A simple sentence template keeps test methods focused An expressive test name is helpful when a test fails

What’s in a Story? | Dan North [This article has been translated into Korean by HongJoo Lee, French by Philippe Poumaroux, Spanish by Adrian Moya, Russian by Denis Oleynik, and German by Julia Kadauke.] Behaviour-driven development is an “outside-in” methodology. It starts at the outside by identifying business outcomes, and then drills down into the feature set that will achieve those outcomes. Introduction Software delivery is about writing software to achieve business outcomes. Usually, the business outcomes are too coarse-grained to be used to directly write software (where do you start coding when the outcome is “save 5% of my operating costs”?) Behaviour-driven development (BDD) takes the position that you can turn an idea for a requirement into implemented, tested, production-ready code simply and effectively, as long as the requirement is specific enough that everyone knows what’s going on. This, then, is the role of a Story. The structure of a story BDD provides a structure for a story. Telling the story 1.

Mocks Aren't Stubs The term 'Mock Objects' has become a popular one to describe special case objects that mimic real objects for testing. Most language environments now have frameworks that make it easy to create mock objects. What's often not realized, however, is that mock objects are but one form of special case test object, one that enables a different style of testing. In this article I'll explain how mock objects work, how they encourage testing based on behavior verification, and how the community around them uses them to develop a different style of testing. I first came across the term "mock object" a few years ago in the XP community. Since then I've run into mock objects more and more. But as often as not I see mock objects described poorly. This difference is actually two separate differences. (In the earlier version of this essay I had realized there was a difference, but combined the two differences together. Regular Tests I'll begin by illustrating the two styles with a simple example.

Get started with testing from top to bottom Image via We are regularly talking to teams who are just starting out with testing their application. Some of them have a few tests, but don’t know where to go next. Others don’t test at all and need help to get started. One team mentioned they felt overwhelmed as there is so much they could test. By starting to test your application from top to bottom you can get over this easily. Start from the top By testing your application you can always be sure the most important steps users can take in your application work. As easy as this sounds we’ve seen teams struggle with coming to that conclusion and then following through. You should start by defining what the most important steps in your product are. Get everyone in your team to write down 8 scenarios they think are the most important ones in your application. All of them should be structured with Given, When and Then steps. Another example would be And one more This should only be the beginning of testing your application.

Learn Ruby on Rails Testing stevecastaneda This course felt like a very solid intro, and left me wanting to research more into using Factory Girl and even RSpec down the line once I get the hang of things. I wish it had a bit more on test driven development, but this course did teach me most of what I needed to know to embark on that journey myself. The challenges seemed a bit more tougher on this one. I ran into syntax issues here and there, and wish the error messages were a bit more descriptive. On the test output tabs, many times the failing test message would get cut off.

Test Your Rails Application Configuration Why? Well, what are the consequences of an improperly configurated application? Poor performance? Loss of revenue? Litigation? Exploring the Configuration Rails application configuration is primarily exposed in config/application.rb via an Application class. [1] Here's an elided example. ... module Foo class Application < Rails::Application ... # Configure sensitive parameters which will be filtered from the log file. config.filter_parameters += [:password] ... end end The application configuration can also be explored in the console, as shown below. $ rails c Loading development environment (Rails 3.2.3) 1.9.3p125 :001 > pry [1] pry(main)> Foo::Application.config => #<Rails::Application::Configuration:0x007ff93bc52010 ... Testing the Configuration I've highlighted the filter_parameters option in the file and the console. In an editor, create a new file named spec/config/application_spec.rb, and write the following two examples. Perfect. Conclusion Notes

Scripted GUI Testing with Ruby If you need to automatically test a user interface, this book is for you. Whether it’s Windows, a Java platform (including Mac, Linux, and others) or a web app, you’ll see how to test it reliably and repeatably. Many automated test frameworks promise the world and deliver nothing but headaches. Fortunately, you’ve got a secret weapon: Ruby. Ruby lets you build up a solution to fit your problem, rather than forcing your problem to fit into someone else’s idea of testing. This book is for people who want to get their hands dirty on examples from the real world—and who know that testing can be a joy when the tools don’t get in the way. eBook This version, last updated Jan 2012, refreshes the RSpec examples for version 2.x.

Wrong Full stack integration testing with Rails3: browser-oriented, JavaScript, continuous integration - Muriel's Tech Blog This post is a complete summary of all my efforts to have a complete and decent solution to test Rails applications. As it is a long post, here you have the table of contents: Rails comes with a natural support for ruby’s Test::Unit, that comes very handy and lightweight. I still think this is a great lib to write your unit tests. So, I wanted to have a great, efficient, portable and easily maintainable solution to test the complete integration of my Rails applications. Well… I found it and I am pretty happy with it so far. The winning stack is: I will explain the use of each one of them, for you to be able to pick exactly what you just need. The goal of this tutorial is not to teach all the tricks of those libraries, but to show you their usage, how they can be useful to you, and how to integrate them together along with simple examples. Ruby and Rails environment This tutorial assumes that you have a working Rails (I tested with 3.2.6, but I think >=3.2.1 is enough) application. /!

Testing JavaScript with PhantomJS I don't think I need to convince you that testing your JavaScript code is a good idea. But, it can sometimes prove tedious to test JavaScript code that requires a DOM. This means you need to test your code in the browser and can't use the terminal, right? Wrong, actually: enter PhantomJS. What exactly is PhantomJS? PhantomJS is a headless WebKit with JavaScript API. As you know, Webkit is the layout engine that Chrome, Safari, and a few other niche browsers use. Installing PhantomJS Installing PhantomJS is actually pretty simple: it's just a single binary that you download and stick in your terminal path. If you're on Mac OS X, there's a simpler way to install PhantomJS (and this is actually the method I used). You should now have PhantomJS installed. I'm seeing 1.7.0; you? A Small Example Let's start with a small example. simple.js Go ahead and and run this code by issuing the following command: You should see the output from the two console.log lines in your terminal window. Loading Pages

Headless Functional Testing with Selenium and PhantomJS Let's build a system for performing functional tests on web applications, using Selenium and PhantomJS. The resulting system will allow us to write easy test scenarios in JavaScript, and test those scenarios both in real browsers and a headless simulator. The obvious downside to Selenium is that it requires a full graphical desktop for any and all tests. To begin, we have to choose a browser control or emulation engine to simulate an end-user. For a long time, the primary player in this field was Selenium, and it still is. The obvious downside to Selenium is that it requires a full graphical desktop for any and all tests. On the opposite end of the spectrum is PhantomJS: A small, but excellent project, running a WebKit engine with full JavaScript access, but without the graphical portion. Selenium can now control PhantomJS in the same way that it does any other browser. PhantomJS, being a full WebKit, covers 90% of your functional testing needs. The choice is absolutely free here.

rb: Rspec views with Rails 3 For a long time, i didn't try with creating apps with BDD or TDD.So i decided to go with rspec, after reading the Rails Views from The Rspec Book.A view spec is a collection of code examples for a particular view template.View specs live in spec/views and render view templates in isolation. Let's generate a fresh app with rails version 3.0.6, rspec 2.3.0 & rspec-rails 2.3.1.As we are using rspec, so remove the test folder from the rails project direcory. If you type rails generate, the only RSpec generator you'll actually see is rspec:install. That's because RSpec is registered with Rails as the test framework, so whenever you generate application components like models, controllers, etc, RSpec specs are generated instead of Test::Unit tests. First i have generated my model with title and description attributes for creating a simple form.rails g model post title:string description:text rake db:migrate rake db:test:prepare Now run the spec:

Angular Modules and RequireJS best practices? Well I'm as blind as a bat with this stuff right now but if I can make progress I'll certainly post it for you! I'm not doing ETE testing yet – trying to plug in unit tests first. I think I got past the problem my gist is referring to and have a new one (the problem I was having was due to the fact that someone (ME) forgot to add the file to the karma config file… once I did that I got past that part of it. Now I'm having a problem with the inject code… Basically I have no idea what I need to put in there or how to do it… I have a controller that has this signature: @DsetCtrl = ($scope, $resource, dimResource) -> I have a service that looks a bit like this: angular.module "Naph", ["ngResource", "$strap.directives", "ng-rails-csrf", "EitDirectives", "EitServices"] angular.module("EitServices", []).factory "dimResource", ($resource, $rootScope) -> (obviously a bunch of code truncated out and I'm just showing the signatures of both) $httpBackend = _$httpBackend_; at null. at null.

Rails Conf 2013 BDD and Acceptance Testing with RSpec & Capybara