qantik
qantik

Reputation: 1097

Mocking socket.io server on Android using Mockito

in order to have some relevant testing data for an Android project that communicates with a socket.io server using the socket.io client side library, I wanted to use Mockito to essentially mock the socket.io server. This however turned out to be harder than I expected and I've not been able to really wrap my head around this problem.

Therefore my question is this task even achievable with Mockito or do I need to resort to other solutions?

Thanks in advance.

Upvotes: 0

Views: 1092

Answers (1)

Alex Shutov
Alex Shutov

Reputation: 3282

The key concept here is to hide real socket implementation behind interface and mock that interface. You should not mock library itself. Say, you have AwesomSocket interface, sending data via socket and AwesomeSockeListener, which purpose is to listen for incoming messages. Concrete implementation will use those interfaces. In unit tests you can easily mock those interfaces, not even touching concrete implementation. Side library is a 'black box' and you only need to test some behaviour, not library.

Upvotes: 2

Related Questions