-1

This link (http://www.taimila.com/blog/ddd-and-testing-strategy/) says: "Feature tests should depend only on the application layer" i.e. presentation layer.

I am trying to understand how BDD fits in when using Onion architecture and TDD to develop a system. I have bought a book, which should arrive at the weekend.

My understanding of Onion and TDD is as follows:

1) Write the tests for the core. Then development of the core so that the tests pass

2) Write the tests for the infrastructure layer. Then development of the infrastructure layer so that the tests pass

3) Write the tests for the application service layer. Then development of the application service layer so that the tests pass

4) Write the tests for the User Interface layer. Then development of the User Interface layer so that the tests pass

At what stage does BDD fit in? My reading is telling me that BDD should be end to end. For example, if Specflow was being used then the step definitions would access the controller. For example (taken from here: https://specflow.org/documentation/Step-Definitions/):

[When(@"I perform a simple search on '(.*)'")]
public void WhenIPerformASimpleSearchOn(string searchTerm)
{
    var controller = new CatalogController();
    actionResult = controller.Search(searchTerm);
}

In this case BDD is only written when the outermost layer of the application (user interface) is written.

However, I was also reading on here about a team that appear (I could be wrong) to develop the Domain Model only and use Specflow for the acceptance tests i.e. the step definitions referenced the Domain Model directly. This is not end to end in my mind.

Question

Are BDD features used to test all layers like this:

MyApplication.UI.AcceptanceTests - includes features and step definitions
MyApplication.ApplicationService.AcceptanceTests - includes features and step definitions
MyApplication.Infrastructure.AcceptanceTests - includes features and step definitions
MyApplication.Core.AcceptanceTests - includes features and step definitions

or do you have one application, which references the UI:

MyApplication.AcceptanceTests

I have done a lot of searching online for my answer, however I have not found it. For example, I have looked here: Using Specflow scenarios for both intergration tests and unit tests, here: Outside-in BDD (with Specflow) and here: BDD: When/where to setup stubs?.

2

write tests for x then development of the x so that the tests pass

Well no, write a single test for a small part of x. Then develop part-of-x so that the test passes. Refactor. Repeat.

BDD is different in that BDD doesn't care unless part-of-x is visible to the end user. BDD wants tests that stay focussed on visible results.

Some diagram it like this:

enter image description here

The main difference between these tests is who they are relevant to. A unit test is relevant to a developer. An acceptance test is relevant to a product owner.

As for layers, that's completely a function of how you organize your code. BDD doesn't care about layers. Layers aren't something a product owner needs to know about. So don't ask them to.

  • Thanks. +1 for reference to the stakeholders. Is it normal to have acceptance tests for the domain model only (if our team is developing the domain model only)? I have come across the term Honeycomb, which may be relevant here. – w0051977 Mar 11 '18 at 18:33
  • @w0051977 Unless you're talking about this I've no idea what you mean. – candied_orange Mar 11 '18 at 18:53
  • I am talking about this: skillsmatter.com/skillscasts/…. I am trying to understand whether "end to end" always means from the UI to the domain model or whether it can mean the domain model only. – w0051977 Mar 11 '18 at 18:54
  • @w0051977 I listened to that whole presentation (the parts where the microphone worked anyway) and I don't know what I was supposed to learn that hexagonal architecture didn't already teach me. Well other then that hexagons can be neatly packed together. If you can teach me I'm all ears. – candied_orange Mar 11 '18 at 19:16
  • Thanks. I am new to Hexagonal architecture so I may of gained a little more. Does "end to end" in a BDD context always mean UI to Domain Model or is it normal to write Specflow features for each layer e.g. UI, app service, Infrastructure etc? – w0051977 Mar 11 '18 at 19:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.