+ Start a Discussion
sdudasduda 

Validation Rules w/ APEX Testing

One major annoyance I've come across with creating APEX test cases are validation rules & required fields. Say I want to create a new Account in a test case, I need to specify all of the required fields for that object - that's fine the first time around. Now, when I go back to test my APEX code a month later, there's a high probability that another required field has been added to the Account object or some new validation was created. This causes my test case to fail, and in turn requires me to update the APEX code.

What approach have other people used to avoid this issue?


David VPDavid VP
That's what tests are for : to determine if your code is still valid and working. If field requirements change, then I am happy that my tests are there to tell me that the code isn't bulletproof anymore (or at least needs to be checked). It allows me to update the code and catch the problem before some user (or god forbid, some manager) does ...

I agree that in a lot of cases, the adding of a required field perhaps doesn't have any impact on your code but if you're running tests, it means you are in a development fase anyway and updating the test cases is a small price to pay.

By the way : this also happens in other programming languages / databases : If you have for example Java or .NET code that is running on a relational database in which a column all of a sudden gets set to a 'not null' requirement, you'll have the exact same scenario ...


-David