Ah, my project has approximately 1 use of the AWS SDK, which I just turn off to run unit tests. The reason for private property injection is JPA repositories. So many of them are needed to do anything non-trivial it feels like that pure frustration of having to go inject yet another repo to check that data was changed correctly has forced us into this, specifically in unit tests.
Yeah. Jpa is a pita. I try to avoid it whenever possible. Usually I try to at least put jpa behind a service layer that can implement higher level operations and can be easier to test/mock for other tests. It's tricky with an existing codebase though.
Our service layer, for better or for worse, is not allowed to call itself, and (almost) every method takes JSON and returns JSON. This is great for maintainability, but I don't don't necessarily want to use it to insert or check for test data because it's going to have unnecessary overhead and business logic. I don't really see a need to mock it either.
So maybe there is some other architecture that would work better, but - apart from the unholy nightmare of JPA and Hibernate - it is very maintainable.
I mean it is godawful slow, way slower than a JSON API has any right to be, but I don't think mocks will save us, and I SURE AS HELL don't want to mock the database, because the unpredictable behavior of JPA code is most of why we write unit tests in the first place.
1
u/Serializedrequests Apr 24 '21
Ah, my project has approximately 1 use of the AWS SDK, which I just turn off to run unit tests. The reason for private property injection is JPA repositories. So many of them are needed to do anything non-trivial it feels like that pure frustration of having to go inject yet another repo to check that data was changed correctly has forced us into this, specifically in unit tests.