Aws-sdk-ios: Help to facilitate testing for AWSCognitoIdentityUserPool

Created on 12 May 2017  路  6Comments  路  Source: aws-amplify/aws-sdk-ios

  • What service are you using?
    Cognito
  • In what version of SDK are you facing the problem?
    2.5.5
  • Language:
    Swift 3.0.1

The AWSCognitoIdentityUserPool throws an exception in it's initializer (- (instancetype)init), ln 123.
This makes it really hard to mock out the object in Swift. Using Objective-C I could swizzle the initializer and construct the object anyway, but that is not a recommended option in Swift. The compiler even pukes out a warning if you implement + initialize.

I have two suggestions in order to help out with mocking this object:

  1. Convert your architecture and make it protocol based so that we can consume the protocols instead of the actual instances. (I know this is not a small thing to ask for, but I gotta try 馃)
  2. Remove the exception from the initializer and let your consumers of your SDK create an "empty" AWSCognitoIdentityUserPool object. Add a log in there if you wish in order to discourage usage of that initializer in other scenarios than tests.
closing-soon-if-no-response

All 6 comments

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

any updates on this?

If there is no desire to change this design what is the recommended way of mocking AWSCognitoIdentityUserPool?

@daviskoh We chose to extend AWSCognitoIdentityUserPool with a protocol. This protocol mapped all functions that we were using ourselves.
That solution had too much maintenance so in the end we chose to wrap all of our Cognito calls inside a service. In our tests we mocked the whole service.

Preferably AWS will wake up see the importance of this. 馃挙

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

This issue has been automatically closed because of inactivity. Please open a new issue if are still encountering problems.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ChrisInspect picture ChrisInspect  路  4Comments

bradgmueller picture bradgmueller  路  5Comments

aTylerRice picture aTylerRice  路  3Comments

fs-bonlook picture fs-bonlook  路  3Comments

victorleungtw picture victorleungtw  路  4Comments