By default, ApprovalTests generates one file per test. However, for @ParameterizedTests, this may not be the desired behavior when using Approvals.verify(object).
The following section demonstrates how to generate multiple files for a single ParameterizedTest, where each file name includes the parameter name.
@ParameterizedTest
@ValueSource(strings = {"parameter1", "parameter2"})
void sampleParameterizedTest(String parameter)
{
// your code goes here
Object output = parameter;
Approvals.verify(output, Approvals.NAMES.withParameters(parameter));
}This code sample ensures that the approved file includes the parameters. For example:
For example:
- SamplesTest.sampleParameterizedTest.
parameter1.approved.txt - SamplesTest.sampleParameterizedTest.
parameter2.approved.txt
Note: As an alternative, consider using Approvals.verifyAll() in combination with @Test.