Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BDD and functional tests

I am starting to buy into BDD. Basically, as I understand it, you write scenario that describes well acceptance criteria for certain story. You start by simple tests, from the outside-in, using mocks in place of classes you do not implement as yet. As you progress, you should replace mocks with real classes. From Introduction to BDD:

At first, the fragments are implemented using mocks to set an account to be in credit or a card to be valid. These form the starting points for implementing behaviour. As you implement the application, the givens and outcomes are changed to use the actual classes you have implemented, so that by the time the scenario is completed, they have become proper end-to-end functional tests.

My question is: When you finish implementing a scenario, should all classes you use be real, like in integration tests? For example, if you use DB, should your code write to a real (but lightweight in-memory) DB? In the end, should you have any mocks in your end-to-end tests?

like image 596
Dan Avatar asked Jun 25 '10 01:06

Dan


People also ask

Can BDD be used for functional testing?

Proponents of BDD use custom tools such as Cucumber to create and maintain their custom DSLs. For contrast, proponents of functional tests generally test functionality by simulating user interactions with the interface and comparing the actual output to the expected output.

What is BDD testing?

What is BDD (Behavior-Driven Development)? Behavior-driven development is a testing practice that follows the idea of specification by example (e.g., Test-Driven Development [TDD]). The idea is to describe how the application should behave in a very simple user/business-focused language.

Which is more suitable for integration and functional testing BDD or TDD?

Starting with the highest level of functionality and letting that drive how you test and develop your application makes your code more flexible and resilient. For optimal development practice, BDD can and should be paired with TDD.

Does BDD replace unit tests?

BDD is a replacement for both TDD and ATDD (and derived from them). The first ever tool for BDD, JBehave, actually started as a replacement for the unit-testing framework JUnit.


1 Answers

Well, it depends :-) As I understand, the tests produced by BDD are still unit tests, so you should use mocks to eliminate dependency on external factors like DB.

In full fledged integration / functionality tests, however, you should obviously test against the whole production system, without any mocks.

like image 81
Péter Török Avatar answered Oct 01 '22 20:10

Péter Török