import com.pholser.junit.quickcheck.runner.JUnitQuickcheck; import com.pholser.junit.quickcheck.Property; class Crypto { byte[] encrypt(byte[] plaintext, Key key) { // ... } byte[] decrypt(byte[] ciphertext, Key key) { // ... } } @RunWith(JUnitQuickcheck.class) public class SymmetricKeyCryptographyProperties { @Property public void decryptReversesEncrypt(String plaintext, Key key) throws Exception { Crypto crypto = new Crypto(); byte[] ciphertext = crypto.encrypt(plaintext.getBytes("US-ASCII"), key); assertEquals( plaintext, new String(crypto.decrypt(ciphertext, key))); } }
Note: The example above presumes the existence and availability of generators for classes String and Key. Find out more about generators in Basic Types and Generating Values of Other Types.
The usual JUnit machinery is honored: @Before, @After, @BeforeClass, @AfterClass, @Rule. Zero-arg public void methods annotated with @Test will also be run.