The Apache Nifi framework has built in unit testing with Junit using test runners. They have a few examples in their code base, but learning first hand really helps. In this post we’ll go over adding unit tests to the JSON Processor that we developed previously.
To start, we’ll checkout the JSON Processor code from Github and then open it up in your favorite text editor. There is already a test package/folder in the project that contains a unit test, rocks.nifi.examples.processors/JsonProcessorTest.java.
When unit testing in Apache Nifi, there are a few items on top of the normal JUnit annotations that are required. While you can unit test with just JUnit, using the built in method in Apache Nifi makes it much easier. In a future post we’ll show you how to unit test using Mockito and JUnit to test helper methods where actually invoking a full processor seems excessive, or if you just don’t want to use Nifi’s test runner.