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
Tag: junit
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,
IntelliJ IDEA with Junit 4.7 “!!! JUnit version 3.8 or later expected:”
When I attempt to run the following test in IntelliJ IDEA I get the message: “!!! JUnit version 3.8 or later expected:” It should be noted that this is an Android project I am working on in IntelliJ IDEA 9. The full stack trace looks like this… Answer This problem happens because Android Platform (android.jar) already contains JUnit classes. IDEA
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
How do you assert that a certain exception is thrown in JUnit tests?
How can I use JUnit idiomatically to test that some code throws an exception? While I can certainly do something like this: I recall that there is an annotation or an Assert.xyz or something that is far less kludgy and far more in-the-spirit of JUnit for these sorts of situations. Answer It depends on the JUnit version and what assert