@Documented
@Retention(value=RUNTIME)
@Target(value=METHOD)
public @interface DataProvider
value()
attribute.
Object
[][]
, a List
<List<Object>>
, or a String
[]
. The test method will be called with each "row" of this two-dimensional array. The test method must be
annotated with @
UseDataProvider
. This annotation behaves pretty much the same as the
@DataProvider
annotation from TestNG.
Note: The name of the test method in the JUnit result will by default be the name of the test method
(annotated by @
UseDataProvider
) suffixed by the parameters, can be changed by customizing
format()
.
Use it directly on test method: Provide all the data for the test method parameters as regex-separated
String
s using String[] value()
.
Note: All parameters of the test method must be primitive types (e.g. char
, int
,
double
), primitive wrapper types (e.g. Boolean
, Long
), case-sensitive Enum
names,
String
s, or types having single-argument String
constructor. The former two are converted using the
valueOf(String)
methods of their corresponding wrapper classes or
valueOf(Class<? extends Enum<?>>, String)
, respectively. This can cause Exception
s at runtime. A
String
must not contain commas! The String
"null" will be passed as null
or String
,
according to convertNulls()
.
If the test method arguments are retrieved from a regex-separated String
[]
, the additional annotation
parameters can be used to customized the generation/conversion behavior.
Modifier and Type | Optional Element and Description |
---|---|
boolean |
convertNulls
Determines if every "null"-
String in value() or returned by the method annotated with @
DataProvider should be converted to null (= true ) or used as String (=
false ). |
java.lang.String |
format
Format pattern to be used to generate test method description.
|
java.lang.String |
splitBy
The delimiting regular expression by which the regex-separated
String s given by value() or
returned by the method annotated with @ DataProvider are split. |
boolean |
trimValues
true if leading and trailing whitespace should be omitted in split String s given by
value() or returned by the method annotated with @ DataProvider , false otherwise. |
java.lang.String[] |
value
Define a list of parameters each as a regex-separated
String for the annotated test method. |
public abstract java.lang.String[] value
String
for the annotated test method.public abstract java.lang.String splitBy
String
s given by value()
or
returned by the method annotated with @
DataProvider
are split.String.split(String)
public abstract boolean convertNulls
String
in value()
or returned by the method annotated with @
DataProvider
should be converted to null
(= true
) or used as String
(=
false
).public abstract boolean trimValues
true
if leading and trailing whitespace should be omitted in split String
s given by
value()
or returned by the method annotated with @
DataProvider
, false
otherwise.String.trim()
public abstract java.lang.String format
com.tngtech.java.junit.dataprovider.internal.placeholder
:
Placeholder | Aliases | Example | Description |
---|---|---|---|
%c |
DataProviderRunnerTest | Simple name of test method class (= Class.getSimpleName() ) |
|
%cc |
com.tngtech.java .junit.dataprovider .DataProviderRunnerTest | Canonical name of test method class (= Class.getCanonicalName() ) |
|
%m |
testIsEmptyString | Simple name of test method (= Method.getName() ) |
|
%cm |
com.tngtech.test .java.junit.dataprovider .DataProviderJavaAcceptanceTest .testIsEmptyString(java.lang.String) | Complete signature of test method (= Method.toString() ) |
|
%i |
13 | Index of the dataprovider test of current test method (starting at 0 ). Useful to generate unique test
method descriptions. |
|
%p[x] |
test, <null>, 4 | Subscripting all parameters by positive or negative index (1.) and range (2.). All indices may either be
positive (starting at 0 and increment) to number parameters from the beginning or negative (starting from
-1 and decrement) to number parameters from the end:
IndexOutOfBoundsException iif any index exceeds the
parameters array length |