1

I'm trying to write a unit test for a post install script class, a class that implements InstallHandler interface. I'm testing two cases: 1- No previous version is defined, for that I just use this:

PostInstallClass postinstall = new PostInstallClass();
Test.testInstall(postinstall, null);

This is working fine.

2- A previous version exists, but for that I'm getting an error System.QueryException: List has no rows for assignment to SObject

PostInstallClass postinstall = new PostInstallClass();
Test.testInstall(postinstall,  new Version(1, 0));

So how to test this second case? How to simulate a test environment where a previous version of a managed package exists? Thanks.

  • 2
    Where is the System.QueryException happening? Your current description does not show that. – Alexander Johannes Oct 2 '14 at 8:41
  • You probably assign the result of a query directly to an instance of an SObject. In general, it'd be a better idea to assign it to a List<SObject> and then handle the 0-results case appropriately. – rael_kid Oct 2 '14 at 10:26
3

The System.QueryException happened in Test.testIntall(postInstall, new Version(1, 0)). But I figured out the problem. I need to put Test.testInstall(postinstall, null) before the other one. So this way it works fine:

PostInstallClass postinstall = new PostInstallClass();
Test.testInstall(postinstall,  null);
Test.testInstall(postinstall,  new Version(1, 0));

This way, the system fiends something (the provisos version) and thus there is no error anymore.

Thanks anyway!

|improve this answer|||||
  • That is an interesting catch! – rael_kid Oct 2 '14 at 13:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.