I use JUnit4 with JUnitParams for testing and I want to know more about the usage of the @TestCaseName
annotation. I understand the usage of @TestCaseName
with the @Parameters
annotation, but I want to know about how to use @TestCaseName
with the @FileParmeters
annotation.

- 9,678
- 13
- 71
- 102
1 Answers
@TestCaseName
allows you to modify how the name of the test case is presented in reports (eg. in your IDE or in the Maven Surefire report). The default naming is {method}({params}) [{index}]
. You can use placeholders to create your own test case names. See Javadoc of junitparams.naming.TestCaseName#value
:
A template of the individual test case name. This template can contain macros, which will be substituted by their actual values at runtime.
Supported macros are:
Lets assume, that we are testing Fibonacci sequence generator. We have a test with the following signature
- {index} - index of parameters set (starts from zero). Hint: use it to avoid names duplication.
- {params} - parameters set joined by comma.
- {method} - testing method name.
- {0}, {1}, {2} - single parameter by index in current parameters set. If there is no parameter with such index, it will use empty string.
@Parameters({ "0,1", "8,34" }) public void testFibonacci(int indexInSequence, int expectedNumber) { ... }
Here are some examples, that can be used as a test name template:
{method}({params})
=> testFibonacci(0, 1), testFibonacci(8, 34)fibonacci({0}) = {1}
=> fibonacci(0) = 1, fibonacci(8) = 34{0} element should be {1}
=> 0 element should be 1, 8 element should be 34Fibonacci sequence test #{index}
=> Fibonacci sequence test #0, Fibonacci sequence test #1
@FileParameters
does not have any relation to @TestCaseName
- it's simply a way to provide parameters to a test method from a file. Using the example above, instead of @Parameters
you could use @FileParameters("/path/to/file.txt")
and have a /path/to/file.txt
with content
0,1
8,34
to achieve the same results.

- 9,678
- 13
- 71
- 102