File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Documenting unit test cases

 
Pradeep bhatt
Ranch Hand
Posts: 8927
Firefox Browser Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do we document unit test cases? Do we identify the class/method name while documenting unit test cases.
Thanks
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not sure I understand your question.
I typically name a test method so that it becomes obvious which scenario I am testing, such as testSquareOfTwo or testThrowsExceptionForNegativeValue. Besides that, the tests are typically so easy to read, that they don't need more documentation.
Can you give us an example of a test you want to document further?
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 33671
316
Eclipse IDE Java VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pradeep,
There are some common conventions that help with this. Unit test classes are named with the name of the class + the word test. So HelloTest.java would be tests for the Hello class. This documents which class the tests pertain to.
Unit test methods are usually named with test + the name of the method + any extra information. Some people append underscores between the parts. So testMethodForNull would test the method "Method" for the condition where null is passed in.
 
Nathaniel Stoddard
Ranch Hand
Posts: 1258
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This may be way off-topic for you. But, you could also manage traceability relationships in some requirements management tool like RequisitePro. That way, you could tell exactly what unit tests are associated with the methods in your components, etc. It sounds like you are looking for something that is more coupled to your source code though.
 
Pradeep bhatt
Ranch Hand
Posts: 8927
Firefox Browser Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your replies.
My manager want to me to list the unit test cases in a document with a brief description. Is this the process normally followed? :roll:
I thought we just code the unit test case in the class. Simply, I want to know if documentaion is required, can't I directly code the test case.
 
Warren Dew
blacksmith
Ranch Hand
Posts: 1332
2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Pradeep Bhat:
My manager want to me to list the unit test cases in a document with a brief description. Is this the process normally followed? :roll:

Yes - where the document is the source file for the test class and the brief description is the name of the test case. But somehow, I don't think that's what your manager has in mind....
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Pradeep Bhat:
My manager want to me to list the unit test cases in a document with a brief description. Is this the process normally followed? :roll:
It sounds like your boss wants to check a checkbox in his deliverable list... Just try to be as brief as you can -- it's probably of no use to try getting him to forget the document completely (assuming that your process requires such a document among the deliverables).
 
Simon Brown
sharp shooter, and author
Ranch Hand
Posts: 1913
6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If, like Ilja, you've been using meaningful names for your unit tests, take a look at TestDox which will create a "formatted" version of your test classes and methods.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Pradeep Bhat:
Thanks for your replies.
My manager want to me to list the unit test cases in a document with a brief description. Is this the process normally followed? :roll:

Write a small perl script which traverses your test classes and generates

testMethodFooThrowsExceptionWhenNullParameterPassed()
Test that method foo throws exception when null parameter passed.

from them.
 
Tina Coleman
Ranch Hand
Posts: 150
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Run JavaDoc on your test classes, if you have any sort of method description there. If you're slick, then you can apply a transform on the documentation to get a document in exactly the format your boss wants. If you're like me, and not slick, at least you've got an easy set to copy/paste from.
 
Pradeep bhatt
Ranch Hand
Posts: 8927
Firefox Browser Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your replies.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome!
So tell us - what will you do?
 
Pradeep bhatt
Ranch Hand
Posts: 8927
Firefox Browser Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wrote the test code and then copied the method description into a document. Sorry, I do not know PERL.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Pradeep Bhat:
Wrote the test code and then copied the method description into a document. Sorry, I do not know PERL.

Well, with Java regular expressions, it wouldn't be hard to automate, either. It's just even simpler using Perl...
 
lakshmi bvr
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

can u follow like this, just write test case id, test case name with the descripttion, actual result of each and every function in the excel sheet or word document. i hope u can follow like this.
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic