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))); } }
The usual JUnit machinery is honored: @Before, @After, @BeforeClass, @AfterClass, @Rule. Zero-arg public void methods annotated with @Test will also be run.