Junit Out and OutOfMemoryError

I am running some JUnit tests for my applications. Each test has a for loop calling the corresponding method 10,000 times. Proven methods produce a lot of logging. These logs are also automatically collected by JUnit as test output. This situation applies to OutOfMemoryError, because the line buffer in which JUnit stores the output becomes too large. I don’t need these logs during the tests, so if there is a way to tell JUnit "do not save program output," that will be enough. Any ideas?

+5
source share
6 answers

What type of logging are you using? Is there a way to override the default log behavior to just ignore all log messages?

+3
source

Some options:

  • Change your log so that it is deleted in the file instead of the standard output.
  • Increase the maximum heap size with -Xmx <some number>M, for example -Xmx 256M.
+1
source

. -Xmx256m -Xmx256m .

0

. , , ( ). , . ( ).

0

, , , , :

"logging" System.out.println() System.err.println(), , , stdout stderr .

// Save the original stdout and stderr
PrintStream psOut = System.out;
PrintStream psErr = System.err;
PrintStream psDevNull = null;
try
{
    // Send stdout and stderr to /dev/null
    psDevNull = new PrintStream(new ByteArrayOutputStream());
    System.setOut(psDevNull);
    System.setErr(psDevNull);
    // run tests in loop
    for (...)
    {
    }
}
finally
{
    // Restore stdout and stderr
    System.setOut(psOut);
    System.setErr(psErr);
    if (psDevNull != null)
    {
        psDevNull.close();
        psDevNull = null;
    }
}

, , JUnit , :

ant test &> /dev/null

Ant/JUnit, , , , , , , . , / System.out System.err , Ant JUnit.

0

If this helps, setting outputtoformatters = "no" solved all my memory problems (in Ant 1.7.1 this prevents the output generated during testing to test formats).

0
source

All Articles