How to Create a Designated Keychain for Testing Purposes?

I wrote a Keychain controller that add, delete and fetch keychain items using SecItemAdd(_:_:)and related APIs with data protection keychain enabled (kSecUseDataProtectionKeychain). I am using it in a macOS Cocoa app.

I am using Swift Testing to write my tests to ensure that the controller works as expected.

As I understand, I should create my own keychain for testing rather than use the actual keychain in macOS. Currently, I created a separate keychain group (e.g. com.testcompany.testapp.shared) and added it to myapp.entitlements file so that the tests pass without failing because of the missing entitlement file.

SecKeychainCreate(_:_:_:_:_:_:) and SecKeychainDelete(_:) API are deprecated with no alternative provided in the documentation. I noticed SecKeychain class but documentation doesn't explain much about it.

How should I test my keychain controller properly so that it does not use the actual macOS keychain, which is the "production" keychain?

How to Create a Designated Keychain for Testing Purposes?
 
 
Q