1
votes

I need to test multiple call-outs that return XML. Storing the XML inside my unit tests' mock class is not a great solution.

I'm wondering if there's another Salesforce object type I could paste the XML into that is accessible during unit tests. I know already that PageReference's getContent() doesn't do anything during unit tests (bummer).

Of course, of Apex allowed line-breaks inside string literals it would be easier to cut and paste the XML, but alas...

2

2 Answers

2
votes

Store the XML in a Static Resource, and then query the StaticResource object from your test code:

StaticResource sr = [select Body from StaticResource where Name='Test_XML' limit 1];
String xmlString = String.valueOf(sr.Body);
Dom.Document doc = new Dom.Document();
doc.load(testXML);
2
votes

For testing classes which do xml parsing I create simple

final static string xmlString = 'xml goes here';

in this testing classes. Then I use it by passing this string into methods which perform xml parsing.

Why do you need to invent a bicycle?