Skip to content

Latest commit

 

History

History
37 lines (29 loc) · 1.41 KB

ParameterizedTest.md

File metadata and controls

37 lines (29 loc) · 1.41 KB

How to use Approvals.verify in Parameterized Tests

Contents

Introduction

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.

Sample Code

@ParameterizedTest
@ValueSource(strings = {"parameter1", "parameter2"})
void sampleParameterizedTest(String parameter)
{
  // your code goes here
  Object output = parameter;
  Approvals.verify(output, Approvals.NAMES.withParameters(parameter));
}

snippet source | anchor

This code sample ensures that the approved file includes the parameters. For example:
For example:

  1. SamplesTest.sampleParameterizedTest.parameter1.approved.txt
  2. SamplesTest.sampleParameterizedTest.parameter2.approved.txt

Note: As an alternative, consider using Approvals.verifyAll() in combination with @Test.