This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Post-Development Unit Testing through DbC Comments

 
Cody Johnson
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34095
337
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34095
337
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34095
337
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic