apex-enterprise-patterns / fflib-apex-common

Common Apex Library supporting Apex Enterprise Patterns and much more!
BSD 3-Clause "New" or "Revised" License
913 stars 517 forks source link

Provide ability to skip dml operations using default SimpleDML class #278

Closed stohn777 closed 4 years ago

stohn777 commented 4 years ago

Add @TestVisible feature to default SimpleDML class that easily enables skipping of DML operations during mock-based unit testing. Workaround was writing inert, mock IDML class without any DML operations.

See fflib_SObjectUnitOfWorkTest for example usage. Snippet here.

    // Within the scope of a unit test.
    fflib_SObjectUnitOfWork.SimpleDML dml = new fflib_SObjectUnitOfWork.SimpleDML();
    dml.setExecuteDMLOperations(false);

    // Where MyApplication is an extension of fflib_Application per related Samples
    MyApplication.UnitOfWork.setMock(new fflib_SObjectUnitOfWork(MY_SOBJECTS, dml));

Significant code changes in fflib_SObjectUnitOfWork.SimpleDML and new lines 71 through 136 in fflib_SObjectUnitOfWorkTest.

fflib_SObjectUnitOfWork includes whitespace, indentation consistency change.

stohn777 commented 4 years ago

Although the intent was providing a very simple on, off switch for DML operations during unit testing, the changes is not as concise as desired, given the comparable effort for the other means of bypassing DML, and does intrude upon reasonable engineering principles.