function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Manuel S.Manuel S. 

Testing Class, that calls methods from other classes



I have a problem while testing my classes.

I need an average of 75%, but here is the problem.


Following structure is given:


Class 1 with TestMethod and entrypoint (Batch)

Class 2 for generate a XML (parser)

Class 3 for sending a webserive callout.


Class 1 call Class 2 to get an XML

Class 1 call Class 3 with the generate XML from Class 2


All this work fine in my normal tests, but with the TestMethods ;(

In individual tests (all have a TestMethod) all this classes get over 75%.


So I start the TestMethod from Class 1. It reads data and generate new data.

Then it calls a method of Class 2 to get an XML.

The XML comes returns and Class 1 calls Class 3 to callout it.


At the results of the test Class 1 gets 78%, Class 2 gets 14% and Class 3 gets 100% ==> average 39% and fail.


The reason why Class 2 gets 14% is, that I call one of 15 method in the class. So the test read 70 of 500 lines of code (the method), but why ? I call one method (plus constructor) not all 15.


Can I get the 75% without copying all methods from the central parser class (Class 2) into my seven batch-classes, that use it ?

(Class 1 is one of seven batch-classes and all useing this parser).


The testing is not a good friend of modular programming, isn´t it ? ;)








The reasons that you are seeing the low percentages is that the results are only for code that is exercised by your test class.  As long as your other batch classes have tests that cover the other 14 methods you will be fine.


You can run all tests in an org to see the real code coverage situation.