Advice on BDD for iOS needed

117 Views Asked by At

Inspired by this issue on objc.io I decided to try out BDD on my new project. Here is my problem: I want to test that MYCredentialStorage somehow persists credentials I ask it to store, namely that next time app is launched I would get the very same credential. MYCredentialStorage uses keychain, so I could mock it and verify that SecItemAdd or SecItemUpdate functions are called, but I am not supposed to test (or know of) MYCredentialStorage’s private methods, right?
I’m sure I’m not the only one faced this problem, so I’m asking for your advice since I’m very new to BDD. Thank you in advance.

1

There are 1 best solutions below

0
On BEST ANSWER

From the comments

Michał Ciuba wrote:

Take a look at another article from the same objc.io issue - dependency injection: objc.io/issue-15/dependency-injection.html. Basically you can inject a mock of keychain into MYCredentialStorage (but maybe you'll need to create a wrapper for SecItem* methods).

Ben Flynn wrote:

I agree with @MichałCiuba - there's no generic way to express that an item will persist between executions of your app. If you're going the DI route, I'd do what he says. If you aren't doing DI, I wouldn't be shy about mocking the keychain storage or your private methods. I'd be explicit in the naming of the test to express exactly what the expectations are.