Design By Contract (DBC ) Vs Junit.

I want to do a small Proof of Concept on useful Design By Contract tool . Can any one know which is good ?I also want to know the diff between Junit and DBC?
[171 byte] By [planswerme] at [2007-9-30 20:41:41]
# 1

There are tools that add DbC to Java. Google found this article:

http://www.javaworld.com/javaworld/jw-02-2001/jw-0216-cooltools.html

http://c2.com/cgi/wiki?DesignByContract

http://leepoint.net/notes-java/15principles_and_practices/20design_by_contract.html

http://portal.acm.org/citation.cfm?id=832856

iContract was the tool, but I don't think it's easily available anymore:

http://blog.taragana.com/index.php?p=62

I personally don't think that's a great loss. Bertrand Meyer made his name on this idea, but IMO it hasn't gone anywhere or made an important difference. Of all the languages I know, only Meyer's Eiffel supports it as part of the language syntax. Even Eiffel developers turn off pre- and post-condition checks in production because they tend to have a bad effect on performance. They're little more than logging statements when that's the case.

Academics love it, but they seem to be the only ones who do.

I'd much rather have a complete set of JUnit tests than DbC support. Tests give you the best indication possible that your code is working before you deploy. Fail a test? Fix it before you deploy? Find a new bug? Add a new test that exposes it and then fix the bug - you'll never see it again. JUnit test suites are living things that grow with your code. They're the safety net that let you refactor with confidence. I think JUnit is a much better idea than DbC ever was.

%

duffymo at 2007-7-7 1:30:41 > top of Java-index,Other Topics,Patterns & OO Design...
# 2

Forgot to point out the difference between DbC and JUnit:

DbC was intended to guarantee correctness of your methods at runtime by checking pre-conditions (requirements for user input), post-conditions (guarantees for method output), and invariants (things that should never change in object state). These can all be disabled at runtime in Eiffel.

JUnit is a separate code branch for your application that tests each class and method you've developed, using both "blue sky", error, and exceptional conditions. These are usually compiled and run at build time. Successful deployment of the application is contingent on 100% correct JUnit tests. If any tests fail, the code isn't deployed. This can be automated using Ant build.xml scripts.

So DbC would operate at runtime if you left it turned on. JUnit is a precondition for deploying the app at all.

I prefer JUnit.

%

duffymo at 2007-7-7 1:30:41 > top of Java-index,Other Topics,Patterns & OO Design...