apex-enterprise-patterns / fflib-apex-common

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

Coverage of UnitOfWork class #480

Closed RafaelBAraujo closed 6 months ago

RafaelBAraujo commented 6 months ago

Describe the bug Some projects or clients require that custom implementations of Apex code should have 80% or more coverage. When executing all test classes, the fflib_SObjectUnitOfWork class is covered by only 78%. Some methods aren't tested at all, making it harder to meet code compliances.

To Reproduce

Steps to reproduce the behavior:

  1. Create a scratch org
  2. Deploy fflib library
  3. Run all tests
  4. See that fflib_SObjectUnitOfWork has 78% of coverage and methods such as add(), RelationshipByExternalId.resolve(), SendEmailWork.registerEmail(), SimpleDML.dmlUpdate(), SimpleDML.dmlDelete(), SimpleDML.emptyRecycleBin(), UserModeDML.dmlInsert(), UserModeDML.dmlUpdate(), UserModeDML.dmlDelete(), fflib_SObjectUnitOfWork.registerRelationship(SObject, Schema.SObjectField, Schema.SObjectField, Object), fflib_SObjectUnitOfWork.registerDirty(SObject, Schema.SObjectField, SObject), fflib_SObjectUnitOfWork.registerPublishBeforeTransaction(SObject), fflib_SObjectUnitOfWork.registerPublishBeforeTransaction(List), fflib_SObjectUnitOfWork.registerPublishAfterSuccessTransaction(List), fflib_SObjectUnitOfWork.registerPublishAfterSuccessTransaction(SObject), fflib_SObjectUnitOfWork.registerPublishAfterFailureTransaction(SObject), and fflib_SObjectUnitOfWork.registerPublishAfterFailureTransaction(List) methods are all uncovered.

Expected behavior -- not applicable --

Version Latest release from Dec 2022

daveespo commented 6 months ago

This topic comes up from time to time -- please read #239

Further discussions in other filed issue about test coverage often come back to the fact that some of the entities that fflib_SObjectUnitOfWork support are not testable without additional metadata. For example, there are no "Standard" Platform Events to exercise the SOUOW support for Platform Events. We'd have to add a Platform Event to the project purely for test coverage and that is not a path that we're going to consider. Similarly, we've moved farther and farther away from doing actual DML operations in our test methods due to challenges that some folks have with validation rules or other limitations that their org admin has applied to those objects.

In short, raising the coverage level is always welcome and we'll gladly review a PR if you submit one (keeping the above considerations in mind). For example, over in #366 and #290 some additional coverage was added by a community contributor.