j8unit

Enhancement for JUnit4 to take advantage of Java 8

This project is maintained by j8unit-team

J8Unit In A Nutshell

J8Unit for API user

J8Unit for API developer

J8Unit combines the power of JUnit4 and Java 8. Briefly spoken, it comes along with:

You can read a brief 5-minute description in the J8Unit’s README. right here in the below sections.

Spiced with few more information, you can read a condensed 15-minute description in J8Unit in a Nutshell. Depending on whether you are using an existing API or you are programming a new API, you should focus on the according chapter.

If you are interested in details, you should dive into the comprehensive descriptions or just read the J8Unit cover story of the Java Magazin 2.16.

J8Unit combines the power of JUnit4 and Java 8. Shortly spoken, it comes along with:

You can read a brief 2-minute description right here in the below sections. You can read a condensed 5-minute description in the J8Unit in a nutshell.

The next sections give a brief summary of these features. Each feature’s extended description is given on a separate page.

Java-8-Based TestClass Model

One of the new features of Java 8 is the default implementation of interface methods. Obviously, such methods can be tests too; However, JUnit4 does not detect these methods. Fortunately, the JUnit4 TestClass model only needs a slightly modification to do so.

The J8Unit TestClass model provides this indispensable extension just by additionally scanning for all @Test annotated default methods – unless overridden by a more specific method within the given test class or any of its super classes.

In result, J8Unit allows you to group tests within certain interfaces.

package org.junit8.examples;

import org.junit.Test;
import static org.junit.Assert.assertTrue;

public interface ReusableTests {

  @Test
  public void foo() {
    /* arrange */
    // [...]
    /* act */
    // [...]
    /* assert */
    assertTrue(...);
  }

}

```java package org.junit8.examples;

import org.junit.runner.RunWith; import org.j8unit.runners.J8Unit4;

@RunWith(J8Unit4.class) public class MyTests implements ReusableTests, SomeOtherTests, FurtherTests {

// additional tests

}

Even more, tests can be easily reused independently of a specific test class hierarchy.

The Reusable Tests API

Admittedly, reusing tests does not make sense if the behaviour is absolutely the same each time it is invoked. Doing so is nothing else than a multiple execution of the same test.

The J8Unit Test Runners

Unfortunately, JUnit4 does not provide injection of the test class model to used; Thus, when running J8Unit tests you have to specify an according test runner that is aware of the extended J8Unit TestClass model.

J8Unit provides such runners for each common use case:

simply scans for all @Test annotated default methods of each (either directly or indirectly) implemented interface of the given test class.

In order to allow JUnit4 to detect @Test of

this package contains the indispensable extension of {@link org.junit.runners.model.TestClass} in order to

In addition to the JUnit4 TestClass model, J8Unit is able to detect test methods which are specified as default interface methods:

The J8Unit TestClass model simply scans for all @Test annotated default methods of each (either directly or indirectly) implemented interface of the given test class.

In result, tests can be grouped within certain interfaces. Even more, tests can be easily reused independently of a specific test class hierarchy.

If you are interested in details, read the explanation at full length.

The J8Unit Test Runners

Any runner that uses the J8Unit TestClass model is able to execute these tests too. Unfortuantely,

In result, any test runner that uses the J8Unit TestClass model is able to execute these tests too.

J8BlockJUnit4ClassRunner & J8Unit4

J8Parameterized

APIConformance

… thus, they allow allow reusage of test methods independently of your test class hierarchy.

The J8Unit Repository

Because of the Java-8-enabled TestClass model, J8Unit provides a very smart way to reuse tests

Currently, we work hard on a j8unit test interface repository. Once it is finished, we want to provide reusable test for any accessible method of any class, enum, interface, or annotation of JDK 8.

Until now, any SDK 8 type has an according dummy j8unit test interface. The first repository release is coming soon and will provide few basic test methods.

After the first repository release, we want to invite others to help us increasing the test coverage by providing implementations of the dummy test methods.

If you are interested in helping, come back in January 2016. We will provide any required information to get your code into j8unit repository.

Additional Assert Methods

(a.k.a. On-Demand Failure Messages)

If you ever wanted to use CharSequence messages when After all is said and done you fell asleep as you are too tired to work further. And then you get up the next morning

Roadmap

See the open issues for a list of proposed features (and known issues).