@RunWith(JUnitQuickcheck.class).public methods with a return type of void on your class, to represent the individual properties. Mark each of them with the annotation @Property. import com.pholser.junit.quickcheck.runner.JUnitQuickcheck;
import com.pholser.junit.quickcheck.Property;
import java.nio.charset.StandardCharsets;
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(StandardCharsets.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.
junit-quickcheck honors the usual JUnit machinery: @Before, @After, @Rule, @BeforeClass, @AfterClass, @ClassRule. It will also run zero-arg public void methods annotated with @Test.