Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
316 views
in Technique[技术] by (71.8m points)

unit 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!

question from:https://stackoverflow.com/questions/18988040/does-tdd-include-integration-tests

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...