+ Start a Discussion

Validation Rules Preventing Install



I have developed an app with a test script. The test script creates test records and gives me 100% test coverage for the app in my developer environment.


However the creation of those records in the test script are creating problems when testing the install of my app in another org with validation rules against the record types.


For instance, my app is dealing with activities. An org has field validation rules for Events. I'm creating event records in the test script, but the records created in the script do not satisfy the validation rules in the client org, so the installation is failing upon install.


I'm surprised to learn that there is not much discussion on this topic, i've looked everywhere.


So i think i may be doing things wrong, or maybe i'm approaching this a little differently than what is common practice.


Should i be querying for existing records, should i be creating them in my test script, or both?


Please reply if you have any insight as to what the common practice is when developing test scripts for packages.


Thank you very much. :)


I believe there's no elegant solution to this problem. 

Quote from the packaging guide:


"If a subscriber creates a validation rule, required field, or trigger on an object referenced by your package, your test might fail if it performs DML on this object. If this object is created only for testing purposes and never at runtime, and the creation fails due to these conflicts, you might be safe to ignore the error and continue the test. Otherwise, contact the customer and determine the impact."


There used to be an "Ignore Apex errors" checkbox that an installer could check, I don't see it anymore. It seems like Apex exceptions are ignored by default. 

If you create a managed package, unit test failures won't negatively affect customer's org - they still will be able to deploy other code/apps into the org.