JUnitParams can be very useful in any test type (UnitTest, IntegrationTest, DistributedTest).
1) Add these importsthese junitparams
imports:
Code Block |
---|
import junitparams.JUnitParamsRunner; import junitparams.Parameters; import junitparams.naming.TestCaseName; |
2) Add this to ) Add {{@RunWith(JUnitParamsRunner.class)}}
to your test class:
Code Block |
---|
@Category(DistributedTest.class) @RunWith(JUnitParamsRunner.class) @SuppressWarnings("serial") public class CreateAndLocalDestroyInTXRegressionTest implements Serializable { |
3) Use both `@Parameters` and `@TestCaseName` on @Parameters
and @TestCaseName
on test method(s) using parameters:
Code Block |
---|
@Test @Parameters({"true", "false"}) @TestCaseName("{method}({params})") public void testSomeBehavioruserFilesAreBackedUp(final boolean valueuseRelativePath) throws Exception { |
This results in nicer test names in the results (ex: ClientDeserializationCopyOnReadRegressionTest):
Code Block |
---|
ClientDeserializationCopyOnReadRegressionTestFileSystemBackupWriterTest (org.apache.geode.internal.cache.backup) testCopyOnReadWithBridgeServeruserFilesAreBackedUp(true) testCopyOnReadWithBridgeServeruserFilesAreBackedUp(false) |
You can also use Strings that represent enums
(ex: CreateAndLocalDestroyInTXRegressionTest):
Code Block |
---|
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) { |
And the results of running with enums
look look like this:
Code Block |
---|
CreateAndLocalDestroyInTXRegressionTest createAndLocalOpShouldCreateEventWithNewValue CreateAndLocalDestroyInTXRegressionTest.createAndLocalOpShouldCreateEventWithNewValue(LOCAL_DESTROY) CreateAndLocalDestroyInTXRegressionTest.createAndLocalOpShouldCreateEventWithNewValue(LOCAL_INVALIDATE) |
Some good examples
- ClientDeserializationCopyOnReadRegressionTest
- CreateAndLocalDestroyInTXRegressionTest
- FileSystemBackupWriterTest