+ Start a Discussion
ca_peterson_oldca_peterson_old 

Impossible to test code covering __History tables

I've done some development of apex that reads and processes the custom object field history tables and produces that amounts to a cusotmized history related list.

 

That's all well and good, except that it seems that the apex test runner does not track field history, and the oldValue and newValue fields on the history object are not writable.

 

It's a large apex class and has taken the total coverage for my app below 75%. How can I properly test in this situation? Help salesforce!

hisrinuhisrinu

Have you tried updating the values for test records in test methods?

ca_peterson_oldca_peterson_old

Tried that, but the history table entries are never created inside test methods no mater what history tracking I have turned on.

KevinLaurenceKevinLaurence

I have the same problem. Does anyone know of a solution?

ca_peterson_oldca_peterson_old

I created a wrapper class for the __history objects that can be created by hand or from an sObject and that got me over 75% test coverage for the class. It's an ugly hack but it works.

Keith987Keith987

Just hit this problem too. Code coverage is one annoyance; the bigger annoyance is being unable to create the necessary set of unit test cases to be sure my code is working.

 

Seems that testability isn't a priority in this platform.

 

Keith

MyGodItsColdMyGodItsCold

I plan to use 

 

@IsTest(SeeAllData=true) 

 

to allow my testMethod to see data I've previously "staged" so that history comes out right.

 

Has any one else considered or tried this?