Release 2.x‎ > ‎Development‎ > ‎

Testing w/ JUnit

JUnit is a unit testing framework for Java.  It is integrated very well to maven and many IDE's (i.e. NetBeans).

In OpenPTK v2.1, our first JUnit test was added, org.openptk.crypto.CryptoTest.  The test was created based on JUnit 3.x.

In OpenPTK v2.2, this test along with the maven dependencies will rely on JUnit 4.x. A good primer on setting up a JUnit test at:


If using NetBeans IDE, you need to add the JUnit plugin, which will include the jar's for both versions 3.x and 4.x of JUnit.

In order to add a JUnit test to OpenPTK, one simply needs to place the tests in the projects src/test/java directory.  This directory is a sister directory to each projects src/java directory.

As an example:

Source Packages

Test Packages

when maven is run, tests for any packages in the test/java directories will automatically be run.  An example run with test results of the CryptoTest looks like:

$ mvn test
 T E S T S
Running org.openptk.crypto.CryptoTest
* CryptoTest: test AESCrypto
* CryptoTest: test DESCrypto
* CryptoTest: test KeyGenCrypto
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.219 sec

Results :

Tests run: 1, Failures: 0, Errors: 0, Skipped: 0