Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should BDD be automated with unit tests, integration tests, or both?

BDD has been touted as "TDD done right".

However TDD is widely used with unit tests, rather than end-to-end integration tests.

Which kind of test is most appropriate for BDD?

  • Should we write only integration tests?
  • Should we also write unit tests?
    • If yes, should there be multiple unit-tests per scenario?
    • And what a unit test covers multiple scenarios? Is there a way to structure these tests when using a testing framework such as MSpec?
like image 846
Jonathan Avatar asked May 11 '11 00:05

Jonathan


People also ask

Are BDD tests unit tests?

Overall, BDD is unit testing done right. Always write your tests such that they verify the end result from the perspective of the client, without paying attention to how exactly that end result is achieved.

Is BDD integration test?

So to recap Integration test Is a type of system testing. But BDD is a methodology to apply this test to your system. Finally, each methodology has its pros and cons you just need to choose which methodology that fits in your environment.

Is BDD automated testing?

When it comes to testing in a behavior-driven development process, there are a wide variety of automated testing tools that can work with Cucumber or Gherkin requirements to streamline your efforts. Automation is vital to the success of any team looking to implement BDD.

Should integration tests be automated?

Just like unit tests, integration tests are mostly written by developers and can be automated, but they test completely different features. Integration tests are about observing how code sections behave together and “making sure that they speak the same language,” Schneider said.


2 Answers

Which kind of test (integration tests, unit tests) is most appropriate for BDD?

I would use both in two nested loops as described in Behavior-Driven Development with SpecFlow and WatiN

* writing a failing integration tests
    * writing a failing unit test as part of the solution of the integration test
        * making the unittest pass
        * refactor
    * writing the next failing unit test as part of the integration test

    * unitl the integration test passes

* writing the next failing integration tests
like image 161
k3b Avatar answered Sep 28 '22 09:09

k3b


The reason you often see acceptance/integration tests used in the BDD cycle is because many of it's practitioners put a heavy emphasis on mocking and outside-in development. As such they tend need to include both end-to-end integration/acceptance tests as well as unit tests to ensure the total behavior of the system.

When fake objects are being used as collaborators instead of real objects in a unit test, it is quite easy to verify that the isolated unit under test behaves in the proper fashion (that is that it modifies it's state properly, and sends the proper messages). However it can not verify anything more than that in isolation the individual object behaves as expected. As such, an end-to-end acceptance test is then necessary verify that all the objects in the system when used together provide the promised value to the end user.

So basically within this approach unit tests and acceptance tests play the following roles:

Unit Tests - Objects in isolation behave in the proper manner

Acceptance/Integration Tests - All Objects together provide the promised value of the system.

Although I myself am a large proponent of this style of development, it is somewhat independent from the general BDD ideas. In my opinion acceptance/integration tests are only necessary when your isolating your system under test in your unit tests by using mocks and stubs.

like image 38
gmoeck Avatar answered Sep 28 '22 10:09

gmoeck