JUnit 5 assumptions

Assertions verify that expected conditions are met after some executions. In some cases, the assertions may not even be necessary to run. This means that assertions can have assumptions. JUnit 5 provides static methods in the class org.junit.jupiter.api.Assumptions to describe test assumptions. When the assumption is not valid, the org.opentest4j.TestAbortedException is thrown and the test is aborted. There are three groups of static methods in Assumptions, assumeTrue, assumeFalse and assumingThat.

Read More

JUnit 5 dynamic tests

In JUnit 5, we can create dynamic tests that are generated at runtime by factory methods. These methods are annotated with the annotation TestFactory.

The method annotated with @TestFactory must return a Stream, Collection, Iterable, or Iterator of DynamicNode objects. DynamicNode is abstract. It has two subclasses, DynamicContainer is the container of other DynamicNode objects; DynamicTest is a generated test case. DynamicTest is created from a display name and an Executable object. Executable is a functional interface that contains only one method void execute(). DynamicContainer is created from a display name and a collection of DynamicNodes.

Read More

Compile and run Java 9 code using Docker

Java 9 is scheduled to release on September 21. If you want to try Java 9 early-access builds now, you can download them from jdk.java.net and install them locally. However, installing the Java 9 builds makes them the default JDK in your machine, which may affect other applications that depend on the JDK. A better choice is to use Docker. If you don’t have Docker installed, download and install it from docker.com.

The Docker image we are going to use is the official Apache Maven image which supports Java 9. We use the tag 3.5.0-jdk-9 to get the Maven 3.5.0 with JDK 9.

Read More

Use private NPM registry

I just want to share some private NodeJS modules for reuse in my other projects. A simple private registry is a good choice. sinopia is what I used.

The installation is very easy.

$ yarn global add sinopia
$ sinopia &
$ npm set registry http://localhost:4873/

Read More

Add Disqus to AMP site

Now I’m going to add Disqus comments to my AMP site. Disqus already supports this and has an official guide about it. The whole process is smooth with only few exceptions.

  • You need to have a separate domain. This is not an issue for me. If you don’t have an extra domain, you can host your disqus HTML file in GitHub or other places. Or you can use a universal HTML file as discussed in this GitHub issue.

Read More