Unit testing methods and void flows in jUnit

I am new to unit testing. I understood its principles, but I still can’t understand how to check my current project. I need to check void methods while working with java.nio.SocketChannel. These methods are: - initSelector, where I open the selector, binds a new ServerSocketChannel and registers it
- read by reading the data and putting it in the queue (should I write an additional method to check if this data really exists in the queue? And in this case should I write tests for these methods?)
- a recording method that takes data from the queue and writes it to SocketChannel

I can check these methods in order not to throw an IOException, but what else?
And how do I check the run () Thread method? Or is it not unit testing, but a system or something else?

+3
source share
3 answers

Basically, you have two options:

  • if you want to fully use unit methods to use these methods, you must hide specific (hardware-dependent components such as sockets, etc. behind mockable interfaces, and use bullying in unit tests to verify that expected calls with expected parameters are made with by these objects.
  • / /, , , ..

, . , - , , , .. , ( , ) /, , , ( , ).

, run() unit test, . , , , , .

, , , a Callable Runnable, unit test . Executor ( ), concurrency .

+2

, SocketChannel unit test, unit test. ( Mockito) SocketChannel. , .

SocketChannel, , SocketChannelFactory. SocketChannelFactory mock, SocketChannel mock.

run() unit test.

Mockito

+2

run() - , , unit test ( , , , , () ). SocketChannel , SocketChannel; , SocketChannel, .
, , . , , , (read(), write() ..).
, http://code.google.com/p/powermock/.

0

All Articles