4

I am using contracts with C# 4.0 and before I was using lots of unit tests (not with TDD). I am wondering if DbC eliminates the need to write external unit tests?

Personally I find contracts better to make robust frameworks, as the contracts are closely coupled with the code itself, and offers other benefits.

What do you guys think?

starblue
  • 55,348
  • 14
  • 97
  • 151
Joan Venge
  • 315,713
  • 212
  • 479
  • 689

2 Answers2

0

I would argue that it's the other way 'round - unit tests are preferable to programming by contract constructs.

I say that because PoC checks are often expressed as asserts that can be turned off at will in production. (Even Eiffel, Bertrand Meyers' language that has built-in support for PoC, recommends turning them off in production.)

I'd rather have a complete suite of unit tests that test "happy path", exceptional, and edge conditions. They're useful when refactoring in a way that PoC is not.

duffymo
  • 305,152
  • 44
  • 369
  • 561
0

I think that DbC can help you verify part of what unit tests can do in general.

Using DbC will be efficient for stuff like input/outputs validation of methods, and it can save you time.
But for more complex validations (like dependency mocking) it will be simpler with external unit tests.

So I don't think that you can eliminate all external unit testing needs by using them.

jturcotte
  • 1,273
  • 9
  • 9
  • By dependency mocking you mean UI dependency, etc? If so, isn't it a bad practice to end up there in the first place? :) – Joan Venge Jan 29 '09 at 23:01
  • oh no I mean any dependency "hard to control" like a database, the network or another module you want to unit test separately (for test efficiency reasons) – jturcotte Jan 30 '09 at 02:58