-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
UnitTest: make SimpleCacheClient mockable #150
Comments
Thanks @ymwjbxxq! We're talking about what would be best to do here. It seems reasonable to have a trait here, but we'll need to weigh the cost of dynamic dispatch here (BoxFuture is still required for trait async methods on stable rust) versus the testing flexibility. |
@kvcache do the async trait features in rust 1.75.0 mean that we can now have a trait for the cache client without dynamic dispatch? |
@ymwjbxxq we started looking into this and I wanted to check back in with you. We could theoretically make a trait for the cache client, but it would have a ton of functions on it, and the list will keep growing over time. It feels like that might not actually be desirable to "mock" for testing purposes because you'd have to implement so many fns, and any time we added a new one, your test compilation would break. I was thinking about how I might try to do mock testing around this, and wondering if it might make more sense to make a small wrapper in your own application that abstracts the cache client. Then you could have a trait for that, with only the functions that you wanted to be able to mock during tests, and it might have a much smaller surface area and be easier to maintain. Very interested in any more thoughts/ideas on this though! |
Of course, your suggestion is correct, and I can do an integration test, but regardless of your implementation decision, I wonder about this:
How the AWS SDK Rust does it? When I mock DynamoDB, I replace the client and I do not need to mock all.
The UnitTestHelper is
Either way, I am fine if you leave it ununit-testable, and I can always do integration tests. |
Thanks @ymwjbxxq - I hadn't seen the StaticReplayClient before, that is a cool idea. We can look into that. https://docs.aws.amazon.com/sdk-for-rust/latest/dg/testing.html#testing-replay |
Hello Team,
It is impossible to Mock or create a Fake of the SimpleCacheClient (at least for me).
The client is initialised in this way:
When writing code, you should be able to Mock the client or replace it.
If you create a trait with https://crates.io/crates/async-trait, it is possible to replace it or Mock it with a library like https://crates.io/crates/mockall.
With this, the code is testable if you write integration tests that are pretty expensive to run each time.
Thanks,
The text was updated successfully, but these errors were encountered: