Unit Testing Synchronization

Consider the following method:

/**
 * Set whether messages are printed to System.out.     * 
 * @param printOutput True to print, false for silent logging
 */
public void setPrintOutput(boolean printOutput) {
   // Synchronize to messages because this field is used when a message is received
   synchronized (messages) {
      this.printOutput = printOutput;
   }
}

This method is part of a set of several methods that include messages, so I want to write a test that checks that this method is synchronized to messages. Does anyone know how I will do this?

+3
source share
2 answers

I think this is beyond the scope of unit testing, because the entire synchronization point is designed to provide a certain type of connection between two remote code fragments.

, messages, , null, . , .

+3

unit test, message , , ( -, ). @biziclop, . , , , - .

+3

Source: https://habr.com/ru/post/1792312/


All Articles