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

Inconsistent Code Coverage and Test Failures in fflib-apex-common #472

Closed lb14447 closed 8 months ago

lb14447 commented 8 months ago

Describe the bug While deploying the fflib-apex-common library in our Salesforce sandbox, few classes are not meeting the required code coverage, and specific tests are failing. This is preventing successful deployment due to coverage requirements and test failures.

To Reproduce The issue was encountered during deployment of apex-common with specific tests. The deployment environment is full copy Salesforce sandbox, and the deployment is conducted via a CI/CD pipeline.

Steps to reproduce the behavior:

Deploy the fflib-apex-common library to a Salesforce org.
Run specified tests for the deployment.
Observe the code coverage warnings and test failures.

Expected behavior All classes in the fflib-apex-common library should meet the minimum required code coverage (75%), and all tests should pass without errors.

Screenshots and text of error observed Code coverage results and test failure messages are as follows:

fflib_SObjectUnitOfWork: 74.251% coverage, minimum 75% required.
fflib_Application: 0% coverage.
Test Failures:
    fflib_SObjectSelectorTest.toSOQL_When_SystemModeAndChildRelationship_Expect_WellFormedSOQL: Assertion Failed.
    fflib_SObjectSelectorTest.toSOQL_When_UserModeAndUserCannnotReadField_Expect_QueryException: Assertion Failed.
    fflib_SObjectSelectorTest.toSOQL_When_UserModeAndUserCannnotReadObject_Expect_QueryException: Assertion Failed.
    fflib_SObjectUnitOfWorkTest.testDerivedUnitOfWork_CommitDMLFail: Assertion Failed.

Version The latest version of fflib-apex-common available as of today.

daveespo commented 8 months ago

Hi @lb14447,

The topic of test coverage was covered over here #239 -- the most salient comment is https://github.com/apex-enterprise-patterns/fflib-apex-common/issues/239#issuecomment-925766112 -- the largest challenge with getting code coverage above 75% for all classes is that some code paths can't be reached in a "plain vanilla org" (ex. SOUOW supports Platform Events but there are no Standard Platform Events for us to write test coverage against). If you see opportunity to cover lines within a 'plain vanilla' scratch org, please propose a PR with additional test coverage.

As for the test failures in your bug report: we have all tests running against a plain vanilla scratch org on each push to this repo so if you are experiencing test failures, we'll need a better repro case to understand the nature of the failure.