javajunitjunitparams

Create test case name (using JUnitParams) from an array passed as a parameter


Is there a way to print contents of an array (passed as one of test parameters) using the @TestCaseName annotation?

What I mean is that I want this test case

private static final File JAVA_DIRECTORY = get("src/main/java/").toFile();
private static final String[] NOT_ACCEPTABLE_IN_JAVA_DIRECTORY = {"groovy", "css", "html"};

public Object[] filesNotAcceptedInDirectories() {
    return $(
            $(JAVA_DIRECTORY, NOT_ACCEPTABLE_IN_JAVA_DIRECTORY)
    );
}

@Test
@Parameters(method = "filesNotAcceptedInDirectories")
@TestCaseName("Verify that no files with extensions {1} are present in directory {0}")
public void verifyFilesArePlacedInAppropriateDirectories(File directory, String[] unacceptableFiles) {
    assertThat(listFiles(directory, unacceptableFiles, true)).isEmpty();
}

to display as

Verify that no files with extensions [groovy, css, html] are present in directory src\main\java

What I currently get is

Verify that no files with extensions String[] are present in directory src\main\java


Solution

  • It will be possible once the new version is released (1.0.5) - https://github.com/Pragmatists/JUnitParams/issues/70