views:

429

answers:

3

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?

A: 

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
A: 

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.

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