Question

I'm trying to join the behaviour driven development approach, but to use it I need to understand how to think in that way.

I'd like to test it on a new personal project I'm starting right now (I'll use RoR)

The project will provide APIs to collect data from external applications, it will provide an authentication system (devise), several models to collect data as needed, and a payment system to purchase subscriptions which will give some premium-only features.

What kind of tests should I perform in order to cover all these functionalities but DRY?

I thought I should use both RSpec and Cucumber. For Devise I'll follow the documentation on their website, but it's not clear to me what kind of tests should I perform to check the data has been collected correctly and it is displayed correctly to the user and which tools use for that task. Also If you could provide a simple example of how would you organize tests and development for this kind of project will help (i'm not asking about real testing code -because I see it really depends upon the implementation-, but about development process and KIND of tests you would perform). If you need some more details to take a choice please let me know and feel free to invent it since it's for educational purposes.

Was it helpful?

Solution

I don’t think there can be any mention of BDD without someone chiming in that it’s all about the communication. So I’ll be that guy: it’s all about the communication! The real value is the exploration of functionality in accessible terms with different stakeholders to establish what the system needs to do transparently. With everybody talking the same language, it’s much easier to communicate goals. When it comes to implementation, developers know what they’re doing, stakeholders know what they’re getting and there shouldn’t be too many surprises (except for the things you missed / captured incorrectly / haven’t realised yet, perhaps).

So, get out there, speak to your stakeholders and work out what the person commissioning the system wants it do. If this is a solo effort, you're going to need to wear a number of different hats.

Your BDD tests will cover the behaviour of the system - units of desired functionality. You'll still need to do unit tests etc. - no change there.

As product owner, think about what you want the system to do – not how. You likely don’t care how things work, as long as they do work. If you’re a developer, this will likely be the difficult shift in thinking. When I first started looking into BDD, I was convinced that it made sense to go through UI journeys and technical details etc. in scenarios. It doesn’t. That stuff belongs in the step definitions. As developer, you can define all of the how stuff there.

As for keeping it DRY… Write your scenarios exactly how you need to in order to capture the required behaviour. Then you can worry about refactoring and identifying opportunities for step re-use. The use of regular expressions will help here too, to some extent. It’s tempting to go super-imperative and have a whole suite of re-usable steps, but you’ll likely realise it’s all very brittle when a change to a single step ripples through all of your scenarios, not just the one it was supposed to affect. If you're interested into any form of web automation, check out the web automation pyramid.

Useful resources (and lots of examples):

http://books.openlibra.com/pdf/cuke4ninja-2011-03-16.pdf < awesome free eBook – fun to read, too.

http://www.slideshare.net/lunivore/behavior-driven-development-11754474 < Liz really knows her stuff!

http://dannorth.net/2011/01/31/whose-domain-is-it-anyway/

https://www.google.co.uk/search?q=declarative+vs+imperative+BDD < go Team Declarative!

OTHER TIPS

I'm not sure this meets your exact requirements, but this is how I do BDD (example is a webapp):

Pretend you're sitting in front of the computer as a user of your application. Write down the steps you need to perform to achieve one of the use cases, for instance:

Navigate to the system's url Login Select the function you require Enter the relevant data to execute the function Click the button to initiate the function Wait for the system to respond Ensure the data on the screen matches the data you expect.

If any of these steps fail to execute, or the data is incorrect, the test has failed.

Once you have this in a test file, you then use Gherkin/Cucumber/Webdriver to implement the code required to execute each of the steps. Each method of this is re-usable, so once you've implemented login in one place, it should work everywhere you call it.

for testing with cucumber or rspec for devise try this

see this - cucumber/rspec or on github

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top