I recently wrote an API to implement Account/Contact Duplicate/Matching rules for a connected app. It all works fine.
It does the same thing that Salesforce does for these rules. It pretty much follows this example code: https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_Datacloud_DuplicateResult.htm
I'm now trying to write a test class for this but I'm hitting a roadblock.
I need a way to do one of two things:
Create Duplicate and Matching rules through Apex code within the test. I would create them, run the test, then delete them.
Turn Duplicate and Matching rules on and off through Apex code within the test. Same general idea but I could create them beforehand in our testing org.
As far as I can tell there is no way to do this. Am I missing something here?
If this isn't possible then how do I get test coverage on my class. It will only get full code coverage if the call to Database.Insert actually fails with DuplicateErrors.
Edit: I should add that having rules always on and bypassing them with DMLHeader for testing is not an option.