title: Unit testing blocking processes
body: <p>I have a worker processes working on a data queue. A <code>training worker</code> reads and processes data from the <code>training queue</code>. It continues to poll and on the look out for new data written to the queue.</p>
  
  <p>I have implemented the worker as follows:</p>
  
  <pre><code>public static void main(String[] args) {
    startTraining()
  }
  
  public static boolean startTraining() {
    trainingWorker = new WorkerImpl(config);
    final Thread workerThread = new Thread(trainingWorker);
  
    WorkerListener listener = new WorkerListener() {
      public void onEvent(WorkerEvent event, Worker worker, String queue, Job job, 
                          Object runner, Object result, Exception ex) {
        if(event.equals(WorkerEvnet.JOB_SUCCESS) {
          //get data
          //process data
          //send data
        }
      }
    }
  
    trainingWorker.addListener(listener, WorkerEvent.JOB_SUCCESS, WorkerEvent.JOB_FAILURE,
                       WorkerEvent.WORKER_ERROR, WorkerEvent.WORKER_POLL);
    workerThread.start();
    workerThread.join();
  }
  </code></pre>
  
  <p>I want unit tests to see if the worker read the data properly, processed it correctly and successfully sent it. The problem is because of <code>Thread.join()</code>; the call to the main function never returns (as the worker is suppose to run continuously). In this case should I not write unit tests for it? If yes, how can I write some other form of test that will ensure the worker is working  as desired?</p>