0

I need to write unit test of an asynchronous method.

In my case I have client(simply tcp client). It send message to server(tcp server). Server takes this message asynchronously.

I want to get the message the server received and compare the message that client had sent.

How can I do this?

Mainly, I want to learn How to apply TDD to asynchronous methods.

Any help will be greately appreciated.

2 Answers 2

1

If you are attempting to actually send data over a TCP socket between a client and server, this is not a unit test. Unit tests would be when you mock the client to test the server and the mock the server to test the client. You don't need to unit test the TCP protocol not the library that you are using to send the TCP (if you are using a library that has testing).

Using an actual client, server and TCP socket would be an integration test.

Sign up to request clarification or add additional context in comments.

Comments

0

As far as writing junit for asynchronous method is concerned, there won't be any difference technically. I mean you don't have to do technically different here. You just need to verify the output independent of synchronous method. Say a different asynch thread is created for getting image from server, you just need to verify your are getting output without any dependency on any other thread.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.