Mocking GCP DatastoreRepository::performTransaction with MockK

Daniel Bunte
1 min readMar 17, 2022

This is purely a quick Note To Self, so that I can find it again when googling for it 🤓

Let’s assume we’re using the integration of Google Cloud Platform for the Spring Framework and want to test the performTransaction method of the DatastoreRepository. In my case, I wanted to first fetch data and only update if a certain condition was true.

val entity = ... // whatever we want to save
myRepository.performTransaction {
val existingEntity = myRepository.findById(entity.id)
if…

--

--

Daniel Bunte

Leader, self-taught developer with interests in Architecture/Automation/Security.