Better support for testing
Closed this issue · 2 comments
Currently, the Datastore
class is a concrete, final class. Also, the 'Query' type that is used in methods like executeAsync
is mutable and doesn't provide any ways of checking properties of the query, meaning that mocking out the Datastore
dependency is hard (you want to be able to validate that the query you receive has some particular properties in tests, in order to determine how to behave). This means that the only way to test a class that is using it is via actually getting the Datastore
instance to talk to a real, working datastore.
An approach that would make it easier to write unit tests on top of this library would be to:
- Make
Datastore
into an interface - Provide a concrete implementation corresponding to the current code
- Provide a concrete implementation that is an in-memory fake (
FakeDatastore
, maybe), meaning that it would permit users to read and manipulate the data in the datastore 'out of band'.
Would something like that be a possibility?
+1
The Datastore class can be mocked with powermock, assuming you can get the right combination of dependencies lined up (newest betas of mockito v2 have issues).
Another thing I ran into is that it would be really nice to be able to assert against the fields of an insert or update, without having to look at the protobuf level.