Search code examples
unit-testingtddintegration-testing

Does TDD include integration tests?


I'm working on some code that includes database access. Does test-driven development include integration tests as well as the usual unit tests?

Thanks!


Solution

  • Golden rule of TDD says: Never write new functionality without failing test.

    If you are not following this rule, then you are doing TDD partially (like writing unit tests only for several classes in your application). That's better than nothing (at least you know these classes do what required, but you cannot be sure that other parts of application are working and these classes can be integrated with them), but that does not guarantee your application works as expected. So, you need to start each feature with writing failing acceptance test, which guides your application design and defines application behavior (outer loop). While this test fails, the feature is not implemented by your application. Then you should write unit tests for separate units which will be involved in this feature (inner loop). The outer loop verifies that all classes involved in this the feature are working together as expected. The inner loop verifies that each class works as expected on its own.

    Following picture from great book Growing Object-Oriented Software, Guided by Tests demonstrates these two feedback loops in TDD:

    TDD

    And the answer to your question is Yes - TDD includes integration tests. That's the only way not to break the golden rule of TDD.