File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Testing and the fly likes Post-Development Unit Testing through DbC Comments Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Testing
Bookmark "Post-Development Unit Testing through DbC Comments" Watch "Post-Development Unit Testing through DbC Comments" New topic
Author

Post-Development Unit Testing through DbC Comments

Cody Johnson
Greenhorn

Joined: Aug 02, 2004
Posts: 2
We are working on an existing project that has already been developed. We've been asked to use Parasoft's Jtest software to do coding standards as well as unit testing.

A)We are adding essentially a bunch of preconditions and postconditions that check if any of the inputs/outputs are null. Is there any benefit to this? Does anyone know a better/more useful approach to this?

B)We realize that DbC is best used during the development phase, but since this is already developed, is there any value to our efforts? Can any good come about from adding DbC comments post-development?

Thanks for all your time and help!

C.J.
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30919
    
158

Cody,
a) The null @pre checks are the minimum required checks to get JTest to point out fewer errors. Be careful of applying them blindly though. Sometimes it is valid to pass a null. And if you are adding the null @pre check whereever JTest complains about an error, that is equivalent to supressing an error. It doesn't actually make the code more robust unless you change the code.

b) While it is good to document after the fact, it can be overwhelming. You have to go back and think about what the methods do and what contracts you were thinking about when you wrote them.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Cody, do you know *why* you've been asked to "use Parasoft's Jtest software to do coding standards as well as unit testing"? That is, what is your goal of doing so?


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30919
    
158

Ilja brings up a good point. I'd also like to mention that I find JTest's coding standard checking more valuable than its unit testing.
Cody Johnson
Greenhorn

Joined: Aug 02, 2004
Posts: 2
A few guys and I have been asked to simply evaluate the usefulness of JTest on a part of a larger project (just a small test). The current goal is only to make this code more stable. But the overall goal is to find out if Unit Testing can be useful post-development.

I agree with your comments on the coding standards and how they can even add to the code post-development. But I am still just curious if (in post-development) any good can come of using Unit Testing. It is quite a bit of work to re-think every method, in your opinion is this a waste of time?

C.J.
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30919
    
158

Cody,
I think there are two main advantages to using JTest post-development for your use.

1) Evaluate and learn how to use the tool - it is easier to evaluate when you aren't so focused on a coding task and deadline.
2) Fine "problem classes" - any classes with a higher number of errors than similar classes warrants further inspection.

It's a great time to learn how to use DBC, but I don't think it's practical to spend the time to do DBC for lots of already written code.
 
Consider Paul's rocket mass heater.
 
subject: Post-Development Unit Testing through DbC Comments