2011-11-03

Tackling a test in an infinite loop

I had a bug that was causing a unit test to go in an infinite loop. Gradle would not print any output from the test because the standard output stream is captured to a test report.

To debug I used the following two techniques:

1 - I accessed the actual standard output, bypassing Gradle's redirection for this specific situation (this is usually not a good idea):

    PrintStream actualStdout = new PrintStream(
        new FileOutputStream(FileDescriptor.out))
    actualStdout.println("test message")

2 - I placed a pause inside the loop that was not stopping to be able to read the messages and make sense of them in human timescale (1000 milliseconds = 1 second).

    Thread.sleep(1000)
 

No comments: