Reputation:
I've designed Java class that implements some server protocol. For example, it has getProtocolVersion()
method, which return latest protocol version. Object of this class is connected to the server through InputStream
and OutputStream
implementations.
I have a test with stubs for each server command. Every test creates ByteArrayInputStream
and ByteArrayOutputStream
with expected client requests and server responses so I can perform logic unit testing of my protocol implementation with JUnit. It's works but creating fixture (prepare data) for each command test is too boring.
Is it really to use mocking in my case? Is this solution less complex? How to mock data sequences through input and output streams?
Upvotes: 1
Views: 889
Reputation: 30022
You could wrap the Streams
in an object that is easier to create and assert with. This can serve for end-to-end tests.
For unit tests, you can extract the logic into methods that are independently testable without having to setup a complex fixture.
Upvotes: 1