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

Test Case for XML

Akhilesh Trivedi
Ranch Hand

Joined: Jun 22, 2005
Posts: 1526
How to write test cases for XML parsers.

I have an XML file, i parse it and store it in database. A tag may or may not be present, depending on that I may or may not update that particular field. How to write test cases in such scenarios. I mean documenting not automating through any framework.


Keep Smiling Always — My life is smoother when running silent. -paul
[FAQs] [Certification Guides] [The Linux Documentation Project]
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30369
    
150

You aren't testing random scenarios. You supply the XML file with your test. You know what it contains. Which means you have two XML files and two scenarios documented.


[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
Akhilesh Trivedi
Ranch Hand

Joined: Jun 22, 2005
Posts: 1526
Thanks Jeanne. What I mean is XMLs are prone to be recursive. I am not sure of how many tags one-in-one may be there, how do we document such a thing into something definite?
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30369
    
150

Now I understand. It's a bit like testing a loop. To be really thorough: you test zero, one, a number in the middle, the max and one over the max.

With XML, you test the element not there at all, one of the element and two or more of the element. Maybe add 10 (a bunch) of the element as well. The idea is to be representative not exhaustive.
Akhilesh Trivedi
Ranch Hand

Joined: Jun 22, 2005
Posts: 1526
Jeanne Boyarsky wrote: The idea is to be representative not exhaustive.


Makes sense. Thanks!
Gopi Chella
Ranch Hand

Joined: Apr 26, 2010
Posts: 53
Otherwise you can validate that xml against a XSD.


SCJP 1.5
saravanan kanda swamy
Ranch Hand

Joined: Apr 21, 2004
Posts: 33
You can also try
XMLUnit http://xmlunit.sourceforge.net/

http://www.o-xml.org/documentation/o-xml-unit-tests.html
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Test Case for XML