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.
Best Answer
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:
This way, the system fiends something (the provisos version) and thus there is no error anymore.
Thanks anyway!