Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BDD & Test Coverage

I have started writing my first BDD tests for iOS, using Quick and Nimble, and I have a question about test coverage.

I realize that in traditional unit tests, developers aim to have 100% test coverage. However, I haven't read that for BDD. If I am understanding BDD correctly, when I am testing the behavior of my code, then the little details of the implementations don't matter; what matters is that I get the expected outcome from my code, correct?

I started trying to get 100% code coverage, but it seems like I am starting to write brittle tests because instead of focusing on the outcome of my code, I am trying to cover all of the paths that my code can take.

  1. Am I understanding BDD correctly?
  2. Does aiming for 100% code coverage defeat the purpose of BDD?
like image 447
Nick Kohrn Avatar asked Jan 01 '17 17:01

Nick Kohrn


People also ask

What does BDD stand for?

What is body dysmorphic disorder? Body dysmorphic disorder (BDD) is a mental health problem. If you have BDD, you may be so upset about the appearance of your body that it gets in the way of your ability to live normally. Many of us have what we think are flaws in our appearance.

What is BDD example?

Behavior Driven Development (BDD) is an approach that consists on defining the behavior of a feature through examples in plain text. These examples are defined before the development starts and are used as acceptance criteria. They are part of the definition of done.

What are the 3 practices of BDD?

The BDD process moves through three phases—discovery, formulation, and automation—where the acceptance criteria are transformed into acceptance tests that are later automated.

What is the difference between BDD and TDD?

BDD is designed to test an application's behavior from the end user's standpoint, whereas TDD is focused on testing smaller pieces of functionality in isolation.


1 Answers

As mentioned in one of the comment, the core aspect of BDD is to give you tests (that could be automated) that guarantee that your product is doing exactly that what it is supposed to do. And obviously: "not less than that".

And in that sense, BDD plus coverage helps you with making sure that your product is not doing much more than that.

In other words: assuming that all your BDD test pass; and your coverage is 75% ... than that could mean: 25% of your code base are not required in order to provide the behavior specified within your BDD testcases. Meaning: you can have a closer look at those 25% of untouched lines to understand why they are not needed; to then determine if there is a chance to delete same parts of that unused source code.

As in: the 2nd best thing you can do as software developer: delete code from your code base without reducing the functionality of your product.

( and for the record: the best thing that a SW developer can do: add a new feature to his product that attracts new customers - deleting code helps your quality in the long run, but customers pay your salary short, medium and long term )

like image 96
GhostCat Avatar answered Nov 15 '22 08:11

GhostCat