Are unit tests required when you have code contracts?

If you are developing an application using code contracts, you may know that this concept was introduced in Eiffela programming language.

I was very confused by trying this concept in my C # application using System.Diagnostics.Contracts.

The main question for me is the following:

Are unit tests necessary if you have code contracts?

One of the main differences that the unit testing infrastructure usually does not provide is the ability to call private methods (except for the library MS fakesfrom it shims). This is due to the support of composition and the idea that private methods are covered by public method calls.

With regard to the code of contracts, I can announce Contract.Requires, Contract.Ensuresfor private practices.

So why do I need unit testing when I have code contracts whose behavior is very similar.

thank

+4
source share
2 answers

You definitely need to test units. With code contracts, you can only get your static contract check. Where you can use your code, you can do much more.

For example, let's say you are testing a class that depends on IConnectionProvider. What happens when you get GetConnection? Code contracts will not help you with this.

, , . , , .

0

, . , , , , . unit test , , , .

0

All Articles