+ Start a Discussion

Code Coverage Testing With Static Resources Fails During Deployment

Is there a known issue (or have I missed something in the documentation) with code coverage tests and static resources?  If I try to install my managed package and *do not* check the "Ignore Apex test failures" checkbox in Step 3 of 3 the installation will fail on any unit tests that use pre-configured test data coming from static resources.


The test files are wrapped into the installation as static resources, and when I run the code coverage tests from within the Force.com IDE (Eclipse) and / or within the Salesforce UI (Setup > App Setup > Develop > Apex Classes > Run All Tests) everythng passes with flying colors.  But when the coverage tests are run during installation the methods that try to load the static resource files always fail.


The odd thing is that the methods that I'm calling for these code coverage tests (REST calls to a web service running on our servers) work fine if I use the actual URL for our REST endpoint, but if I call the same methods using a URL that points to the static resource (e.g. "/resource/12345/Namespace__MyTestFile.xml") the tests will fail.


To restate things slightly, just to make sure I'm explaining the problem correctly:


-- Code coverage tests are calling all of the same methods using an actual REST endpoint URL and a pseudo endpoint URL that points to a series of static resource URL's.  The unit tests work fine (and pass the code coverage tests during deployment) for the live URL's but fail for the static resource URL's.


-- Both live and static resource URL's pass the code coverage tests when I run them from within the IDE and from the Salesforce development UI's.


Anyone have any ideas why code coverage tests during an install would fail for static resources?  I'm pretty much stumped at this point.


Jerry H.



Sorry for bringing up an old post...

I'm doing much the same thing, I have an offline mode for a REST service which reads in canned REST responses from a static resource.


It looks like the static resources aren't included in your package, therefore when you test during install on a client org the static resources can't be found.

Obviously we don't want to include test resources (either static resources or custom objects specific to testing) in our package, but at the same time we can't do DML on static resources.


Does anyone know the best place to put these canned REST responses?

I want to be able to modify them via metadata API or the WSDL for Selenium testing, but I need to be able to modify them via apex for unit testing.