当前位置: 动力学知识库 > 问答 > 编程问答 >

tdd - Understanding testing (BDD) — Can I skip Unit Test duplicating something that is already covered in certain Integration Test?

问题描述:

Note: There was the similar question before ( BDD And Unit Testing ) but it doesn't have an actual straight answer. Just link to the book.

Assume we test a profile page. User submit his data.

  • Validation failed — we notify him about it, object not updated.
  • Validation passed — he's redirected to profile page with submitted data. Object updated. Cool!

So if I've tested that validations are working properly during BDD do I need to double-check it with Unit Test? Or I can skip it? What will the right thing to do in this case and why?

网友答案:

Integration test checks your parts are working together in right manner.

Unit test covers right functionality of each part itself.

So, there are two parts of the answer:

  1. No, you should not skip it. Integration tests tested your validation in context of the whole page including all its modules. A module that does validation should definitely have Unit Test that test this, as well (in isolation, as Unit Tests do).
  2. You never test same things with Integration tests and with Unit Tests. In integration test you tested the page behaves such and such with certain inputs. In Unit Test you can even ignore you are in a page, if you are testing a self-containing module. Even if that module validates some data and does some decisions. You only Unit Test that validation process and outcome of that decision.
网友答案:

If the validation logic is simple, go ahead and ignore the TDD dogma. You won't gain much from "proper" unit tests.

But if the validation is complex, you probably won't be able to test every corner case in an integration tests (or if you do, the tests will take a very long time to run and be fragile, i.e. break often for various reasons, and when they break it will sometimes be hard to determine why.

Unit tests suffer much less from these problems, so they can be useful to complement the integration tests.

分享给朋友:
您可能感兴趣的文章:
随机阅读: