Currently, the build system includes source files with unit tests depending on the actual build feature set, including options such as ENABLE_WALLET, ENABLE_IPC and BUILD_GUI_TESTS.
This leads to confusion when test results from different builds are aggregated together, for example, in https://my.cdash.org/index.php?project=bitcoin-core. It raises questions about why the total number of tests differs across builds.
The functional tests take a better approach by simply disabling tests for unavailable features.
I believe the unit tests should adopt the same approach.
In light of the ongoing modernization of the test framework (https://github.com/bitcoin/bitcoin/pull/33483 and #35713), I wonder whether those efforts are compatible with this idea.