Search code examples
unit-testingbdd

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?

Solution

  • 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 )