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 Documenting unit test cases Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Testing
Bookmark "Documenting unit test cases" Watch "Documenting unit test cases" New topic
Author

Documenting unit test cases

Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8919

How do we document unit test cases? Do we identify the class/method name while documenting unit test cases.
Thanks
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
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?


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
internet detective
Marshal

Joined: May 26, 2003
Posts: 30537
    
150

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.


[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
Nathaniel Stoddard
Ranch Hand

Joined: May 29, 2003
Posts: 1258
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.


Nathaniel Stodard<br />SCJP, SCJD, SCWCD, SCBCD, SCDJWS, ICAD, ICSD, ICED
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8919

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

Joined: Mar 04, 2004
Posts: 1332
    
    2
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

Joined: Jan 23, 2002
Posts: 11962
    
    5
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).


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Simon Brown
sharp shooter, and author
Ranch Hand

Joined: May 10, 2000
Posts: 1913
    
    6
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

Joined: Jul 11, 2001
Posts: 14112
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

Joined: Dec 12, 2001
Posts: 150
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

Joined: Feb 27, 2002
Posts: 8919

Thanks for your replies.
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
You're welcome!
So tell us - what will you do?
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8919

Wrote the test code and then copied the method description into a document. Sorry, I do not know PERL.
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
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

Joined: Jun 01, 2004
Posts: 6
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Documenting unit test cases