|
| 1 | +<a id="top"></a> |
| 2 | + |
| 3 | +# How to Test a Variety of Values for One Input |
| 4 | + |
| 5 | +<!-- toc --> |
| 6 | +## Contents |
| 7 | + |
| 8 | + * [When to use Approvals::verifyAll()](#when-to-use-approvalsverifyall) |
| 9 | + * [Steps](#steps)<!-- endToc --> |
| 10 | + |
| 11 | +## When to use Approvals::verifyAll() |
| 12 | + |
| 13 | +When you want to test a lot of variations for a single input value. |
| 14 | + |
| 15 | +If you have more than one parameter that you want to vary, check out [Testing Combinations](/docs/how_to/TestingCombinations.md#top). |
| 16 | + |
| 17 | +## Steps |
| 18 | + |
| 19 | +1. Copy this starter text. |
| 20 | + |
| 21 | +<!-- snippet: VerifyAllStartingPoint --> |
| 22 | +<a id='snippet-verifyallstartingpoint'></a> |
| 23 | +```java |
| 24 | +String[] inputs = {"input.value1", "input.value2"}; |
| 25 | +Approvals.verifyAll("TITLE", inputs,s -> "placeholder " + s); |
| 26 | +``` |
| 27 | +<sup><a href='/approvaltests-tests/src/test/java/org/approvaltests/ApprovalsTest.java#L40-L43' title='Snippet source file'>snippet source</a> | <a href='#snippet-verifyallstartingpoint' title='Start of snippet'>anchor</a></sup> |
| 28 | +<!-- endSnippet --> |
| 29 | + |
| 30 | +2. Modify the input container for your chosen values. |
| 31 | +3. Run it, and make sure that you have your inputs wired up correctly. |
| 32 | + |
| 33 | +If they are wired up correctly, you will see a file that looks like this: the lambda is responsible for both the execution and formatting of the result. |
| 34 | + |
| 35 | +<!-- snippet: ApprovalsTest.verifyAllTemplate.approved.txt --> |
| 36 | +<a id='snippet-ApprovalsTest.verifyAllTemplate.approved.txt'></a> |
| 37 | +```txt |
| 38 | +TITLE |
| 39 | +
|
| 40 | +
|
| 41 | +placeholder input.value1 |
| 42 | +placeholder input.value2 |
| 43 | +``` |
| 44 | +<sup><a href='/approvaltests-tests/src/test/java/org/approvaltests/ApprovalsTest.verifyAllTemplate.approved.txt#L1-L5' title='Snippet source file'>snippet source</a> | <a href='#snippet-ApprovalsTest.verifyAllTemplate.approved.txt' title='Start of snippet'>anchor</a></sup> |
| 45 | +<!-- endSnippet --> |
| 46 | + |
| 47 | +4. Replace the "placeholder" with a call to the functionality that you want to test. |
| 48 | +5. Change the TITLE to something meaningful |
| 49 | +6. Run it, and approve the output. |
| 50 | + |
| 51 | +--- |
| 52 | + |
| 53 | +[Back to User Guide](/doc/README.md#top) |
0 commit comments