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
  • 2
    Where is the System.QueryException happening? Your current description does not show that. Oct 2, 2014 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. Oct 2, 2014 at 10:26

1 Answer 1

4

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!

1
  • That is an interesting catch! Oct 2, 2014 at 13:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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