Showing posts with label debugging. Show all posts
Showing posts with label debugging. Show all posts

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)
 

2009-09-25

Idea Factory quote


Debugging: It will become apparent to you many times during a program's evolution that the program is not entirely right. Instead of blaming the program for these faults, strange creatures called bugs are blamed. In this way the programmer remains free of guilt. Debugging, like programming, is an acquired skill and an art.


The Idea Factory, Learning to think at MIT