Resources

Scheduling Junit tests with RunnerScheduler for a concurrent execution

JUnit has a very cool feature called RunnerScheduler.

A custom RunnerScheduler can be set on a ParentRunner to control how child elements are executed. If you are on a Suite, the child elements would be each test class. If you are on a simple class (Junit4 runner) the child elements are all the test methods. Thus, with a RunnerScheduler you are able to control the overall execution of your test flow.

Creating abstract contract tests in JUnit 4

As part of his talk on integration tests J.B. Rainsberger talked about how contract tests can be used to test the interaction between classes when using a mockist approach to developer testing. He wondered aloud if it would be possible to write these kinds of tests using abstract classes and JUnit 4. The answer is yes, with some caveats!

Watch the Screencast

Writing your own JUnit extensions using @Rule

The @Rule annotation allows you to annotate a public field in your test class, which is of type MethodRule. This binding will intercept test method calls like an AOP framework would do and redefine the execution, skip it, or do anything else.
In example, suppose you want to run some concurrency test: you may need to execute your test method on 15 threads each starting at the same time, and then wait for all threads to finish. For those knowing TestNG, this is equivalent to the attribute parallel of @Test.

Beware Mutable Data Points

One of the benefits of JUnit Theories is that they decouple test inputs (data points) from test implementation (Theories). However, this benefit comes at a price: since data points may be reused and modified across several Theories, the way in which one defines mutable data points can cause surprising unexpected behavior.

Inline Assertions in JUnit 4

Inline assertions are powerful technique for inspecting how your system is being tested. Beyond simple test coverage, they allow you quickly check different input values and states while never leaving your editor. This article provides examples and Eclipse code templates to help you adopt this valuable practice.

via FeedbackJunkies.com

New JUnit 4.x Howto + updated JUnit 3.x Howto

Both HOWTOs assume the user knows Java, but not JUnit.

Available at http://pub.admc.com/howtos/junit .

Besides explaining basic usage, the 3.x Howto explains the tricky aspects of 3.x, such as organizing suites and making test classes testrunner-friendly.

Besides explaining basic usage, the 4.x Howto covers good test design and the distinction between JUnit failures and errors.

Tutorial automated testing with JUnit + T2

With the help of T2 utility we can do automated testing with JUnit (yes!). T2 itself is a powerful automated testing utility for Java. It's free (GPL). Using it is quite easy. It can be used as simply as a library from a JUnit test. Check out the quick tutorial here.

JUnit 4.x Quick Tutorial

This is a quick JUnit tutorial for new Java programmers: here.

Reusing Functional Tests - Part 1

Everyone wants to reuse their test code. Reusing test code for functional tests is harder, as tests navigate through many pages in an application. This also means that parts of the tests are similar. This article talks about how you can abstract screens in your application using the Screen Object Pattern.

Reusing Functional Tests - Part 1

JUnit 4 in 60 Seconds

Short and fast introduction to JUnit 4 new features. It shows "annotation based testing", "new exception handling mechanism", "usage of @ignore and timeouts", "new assertion statements" and "usage of JUnit4TestAdapter class" in JUnit 4. It takes only 60 seconds to have a look at. Enjoy it.
JUnit in 60 Seconds