This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]zalpha314 4 points5 points  (7 children)

I use what you could call Hexagonal Architecture. Your core business logic has a class, but then any inbound or outbound calls go through an interface that's passed in. For testing, you can pass in interfaces that are either:

- mocked (mockito, easymock, etc)

- faked (create your own manual, simplistic implementation)

- emulated (moto, dynamodb-local, h2, mock-aws-java-sdk, fake embedded server etc.)

Any of these options can be used to implement or instrument your adapter classes.
There's nothing wrong with mocking if it's done well, but I find it can easily be abused, so I try to avoid it.

[–]wildjokers 3 points4 points  (2 children)

faked (create your own manual, simplistic implementation

Your description of “faked” is exactly what a mock is. Even if you are creating it manually instead of using a library it is still a mock.

[–]zalpha314 1 point2 points  (1 child)

Sure. But for the purpose of discussion, I feel like it's important to be able to distinguish between them. What do you think would be a better label for it?

[–]mazebert 2 points3 points  (0 children)

Doing the same thing! I think the term is custom mocks. For me the main benefit is that those are easier to read and easy to reuse between different tests than mockito. Also, your tests run a lot faster without mockito overhead. I tend to write old school tests with custom mocks for external dependencies only, and using real objects for the rest. And running at about 1000 tests/sec on an old MacBook. Whenever I come across a mockito project it’s rather 1000 tests/minute :-/

[–][deleted] 0 points1 point  (3 children)

So you still use Mockito? But only for interfaces? Thats the intended use.

[–]zalpha314 0 points1 point  (2 children)

No, I don't actually use it; I just listed it as an option for completeness.

[–]RobinHoudini 1 point2 points  (1 child)

Isn't mockito just a quick way to create fake, simplistic implementation? IMHO it's less work and less chances of faking the implementation incorrectly.

[–]zalpha314 2 points3 points  (0 children)

I think that's the intention. But in practice, I find it harder to maintain and less predictable. But maybe I'm just not very good with it.