Skip to content
Advertisement

Tag: junit

JUnit terminates child threads

When I test the execution of a method that creates a child thread, the JUnit test ends before the child thread and kills it. How do I force JUnit to wait for the child thread to complete its execution? Answer After reading the question and some comments, it seems that what you need is a technique for unit testing asynchronous

log4j vs. System.out.println – logger advantages?

I’m using log4j for the first time in a project. A fellow programmer told me that using System.out.println is considered a bad style and that log4j is something like standard for logging matters nowadays. We do lots of JUnit testing – System.out stuff turns out to be harder to test. Therefore I began utilizing log4j for a Console controller class,

Compare Date objects with different levels of precision

I have a JUnit test that fails because the milliseconds are different. In this case I don’t care about the milliseconds. How can I change the precision of the assert to ignore milliseconds (or any precision I would like it set to)? Example of a failing assert that I would like to pass: Answer Use a DateFormat object with a

JUnit: @Before only for some test methods?

I have some common set up code that I’ve factored out to a method marked with @Before. However, it is not necessary for all this code to run for every single test. Is there a way to mark it so the @Before method only runs before certain tests? Answer Just move out the tests that don’t need the setup code

Easy way of running the same junit test over and over?

Like the title says, I’m looking for some simple way to run JUnit 4.x tests several times in a row automatically using Eclipse. An example would be running the same test 10 times in a row and reporting back the result. We already have a complex way of doing this but I’m looking for a simple way of doing it

Advertisement