Good article! Are you not afraid you'll generate too many mocks if your codebase use many dynamo queries? I personally prefer using localstack that mocks ddb, with an init phase and a cleanup after. Less reliant on mock code, and well tested, also it should behave more closely to the final behaviour (arguable).
I'm not mocking the query, just the API, so I have to mock each method (get, put, etc) of the API, but don't need to write individual mocks for each query.
As I wrote in the post, I have experience with localstack. Needing to get each service into the correct state (setup, teardown) for tests to run in a continuous integration pipeline (which now needs Docker or localstack installed, of course) was considerably more work for me on the projects I employed that technique than writing a few jest mocks was. For my money, localstack is nearly as much overhead as just using a non-production AWS account and the latter is considerably easier to debug.
But ultimately my approach is a different approach. I am deliberately avoiding testing the AWS service. I'm only testing my own code - how does it form the correct payload for a call to an AWS service and how does it handle the expected response? That seems appropriate for a unit test. Thanks for reading and your thoughts!
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Good article! Are you not afraid you'll generate too many mocks if your codebase use many dynamo queries? I personally prefer using localstack that mocks ddb, with an init phase and a cleanup after. Less reliant on mock code, and well tested, also it should behave more closely to the final behaviour (arguable).
I'm not mocking the query, just the API, so I have to mock each method (get, put, etc) of the API, but don't need to write individual mocks for each query.
As I wrote in the post, I have experience with localstack. Needing to get each service into the correct state (setup, teardown) for tests to run in a continuous integration pipeline (which now needs Docker or localstack installed, of course) was considerably more work for me on the projects I employed that technique than writing a few jest mocks was. For my money, localstack is nearly as much overhead as just using a non-production AWS account and the latter is considerably easier to debug.
But ultimately my approach is a different approach. I am deliberately avoiding testing the AWS service. I'm only testing my own code - how does it form the correct payload for a call to an AWS service and how does it handle the expected response? That seems appropriate for a unit test. Thanks for reading and your thoughts!