Insert Custom Metadata for Unit Test

  • I have a controller that is querying custom metadata. I'm attempting to write unit tests to test the queries. Is it possible to insert test custom metadata for the purposes of unit tests?

  • At time of writing, it is not possible to insert test custom metadata, unless you use the Metadata API which would also present a challenge in a test scenario. That said, you should not need to. Custom Metadata is Metadata and as such is not affected by the SeeAllData annotation. See this article dedicated to testing custom metadata.

    I would argue the "you should not need to" part solely for the purpose that, in a unit test, I should be able to insert a record for custom metadata (similar to custom setting) and then verify that my code uses the same value. I've voted for the idea mentioned above by Daniel Ballinger and it's now "In Development" so waiting for it :)

    I don't disagree :)

License under CC-BY-SA with attribution

Content dated before 7/24/2021 11:53 AM