JUnit and XML (JDOM)
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Scott_Large
Posted On:   Thursday, March 20, 2003 02:53 AM

I have been having a debate with a few other developers about how to test a method in a class that expects a JDOM element. They say it is ok to read in an XML file and extract the required element but I say it is best to build up the Element in code. Does anyone know the general practice for testing this sort of method? I believe classes should be as self contained as possible and not rely on other parts of the system. Obviously if a class is responsible for parsing an XML file or reading a text file then an external file is needed. What do you people think? Cheers.    More>>

I have been having a debate with a few other developers about how to test a method in a class that expects a JDOM element.


They say it is ok to read in an XML file and extract the required element but I say it is best to build up the Element in code.


Does anyone know the general practice for testing this sort of method?


I believe classes should be as self contained as possible and not rely on other parts of the system. Obviously if a class is responsible for parsing an XML file or reading a text file then an external file is needed.



What do you people think?


Cheers.

   <<Less

Re: JUnit and XML (JDOM)

Posted By:   Anonymous  
Posted On:   Friday, March 21, 2003 10:00 AM

It seems to me that creating the JDOM element in code is


  • easier to do,
  • more reliable (you don't depend on the availability of an external entity), and
  • faster (important if you have many of such tests)


What advantages would using the file aproach have???

Re: JUnit and XML (JDOM)

Posted By:   Anonymous  
Posted On:   Friday, March 21, 2003 06:31 AM

If you method requires a JDOM element, your testcase has to create that. Via code or via parsing doesn´t matter - it´s for test only. (advantages: code=faster, parsing=modifyable). I would do the code.


Just my opinion.

About | Sitemap | Contact