For DistributedTest example, see CreateAndLocalDestroyInTXRegressionTest.
1) Add these imports:
import junitparams.JUnitParamsRunner; import junitparams.Parameters; import junitparams.naming.TestCaseName;
2) Add this to your test class:
@RunWith(JUnitParamsRunner.class)
3) Use both `@Parameters` and `@TestCaseName` on test method(s) using parameters:
@Test @Parameters({"true", "false"}) @TestCaseName("{method}({params})") public void testSomeBehavior(final boolean value) throws Exception {
This results in nicer test names in the results (ex: ClientDeserializationCopyOnReadRegressionTest):
ClientDeserializationCopyOnReadRegressionTest (org.apache.geode.cache) testCopyOnReadWithBridgeServer(true) testCopyOnReadWithBridgeServer(false)
You can also use Strings that represent enums
(ex: CreateAndLocalDestroyInTXRegressionTest):
private enum LocalOperation { LOCAL_DESTROY((region) -> region.localDestroy(KEY), TXStateStub_LOCAL_DESTROY_NOT_ALLOWED_IN_TRANSACTION), LOCAL_INVALIDATE((region) -> region.localInvalidate(KEY), TXStateStub_LOCAL_INVALIDATE_NOT_ALLOWED_IN_TRANSACTION); ... } @Test @Parameters({"LOCAL_DESTROY", "LOCAL_INVALIDATE"}) @TestCaseName("{method}({params})") public void createAndLocalOpShouldCreateEventWithNewValue(final LocalOperation operation) {
The results of running look like this:
CreateAndLocalDestroyInTXRegressionTest createAndLocalOpShouldCreateEventWithNewValue CreateAndLocalDestroyInTXRegressionTest.createAndLocalOpShouldCreateEventWithNewValue(LOCAL_DESTROY) CreateAndLocalDestroyInTXRegressionTest.createAndLocalOpShouldCreateEventWithNewValue(LOCAL_INVALIDATE)