c# - Does code contracts really help unit testing? -
I have a fair amount of knowledge on unit testing. I want to read about code contracts. Does this really help in unit testing? Is it over-rated, especially when we talk about code-contract, help in testing the unit. I specifically mention contracts in .NET 4.0. I use nunit for unit testing.
yes and no . The unit test is basically a contract that says, MyMethod () takes X, and hopes that the result of Y will be, and when it does not happen, then unit tests fail and you will not be able to develop the MyMethod As you are warned, some codes inside this contract help you to write unit tests, because you need to know the requirements of the unit tests rather than the contracts. To make it easier when you type them. However, the correct reason for the code contract is not for you, but for other developers using the API you created. With unit tests you get the proper input and output, but when you leave the code in the wild, unit tests are not released with .dll. Code Contract Other gives developers the benefits of knowing through compiled time contracts and checks, those same requirements. The contract protects against those developers (me) who have not read the law document and are just a horrible tendency to start passing through things, so now they will be actively warned through contracts.
Comments
Post a Comment