• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Testing hierarchical method calls

 
Ranch Hand
Posts: 385
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I implement code that takes XML document and copies required data into Java objects. I have groups that may contain other groups and entries. The calls looks like

buildModel()
calls parseHierarchy()
calls parseGroup()
calls parseEntry()
calls parseHierarchy() - yes yes , recursive call

I write JUnit tests for parseGroup, parseEntry.. but now to test parseHierarchy I would have to submit the data from parseGroup and parseEntry.. And to test buildModel I will have to submit data from all previous tests. The buildModel will fail if there is something wrong with parseHierarchy, parseGroup or parseEntry methods. Testing parseGroup and parseEntry requires lots of test data alone...

I understand that neither parseHierarchy nor buildModel are concerned how to test smaller methods called (since they have their own tests).

How to test code in this situation. According to "Pragmatic Programmer" book if the test code significantly larger than original code then it's probably due to bad code design. How could I improve this design and test everything propertly?

Thanks,
Vladas
 
author & internet detective
Posts: 41878
909
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Vladas,
You don't have to retest all the data from the parseGroup/parseEntry methods. Those tests could be more detailed. In the buildModel test, you could test the overall flow (and whatever it is that buildModel does.)

For example, the parse tests could check for a string index out of bounds case. Build model wouldn't necessarily need that test since it is contained by the smaller methods.

Alternatively, you could just test buildModel since it calls the other methods. (I like your approach better though.)
 
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I assume that ur buildModel() method just calls all these methods
parseHierarchy()
parseGroup()
parseEntry()
parseHierarchy() - yes yes , recursive call

The way I will follow is Unit Test small methods and write a Test for buildModel() using Mock and make sure buildModel() is calling these small methods as intended
[ September 27, 2004: Message edited by: Siva Jagadeesan ]
reply
    Bookmark Topic Watch Topic
  • New Topic