When you want to test a lot of variations for a single input value.
If you have more than one parameter that you want to vary, check out Testing Combinations.
- Copy this starter text.
String[] inputs = {"input.value1", "input.value2"};
Approvals.verifyAll("TITLE", inputs, s -> "placeholder " + s);
- Modify the input container for your chosen values.
- Run it, and make sure that you have your inputs wired up correctly.
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.
TITLE
placeholder input.value1
placeholder input.value2
- Replace the "placeholder" with a call to the functionality that you want to test.
- Change the TITLE to something meaningful
- Run it, and approve the output.
Another way to test a variety of inputs is to use a MarkdownTable
.
Here's an example:
String[] inputs = {"verify json", "verify all", "verify parameters", "verify as json"};
VerifiableMarkdownTable table = VerifiableMarkdownTable.withHeaders("Input", "Camel Case", "Snake Case",
"Kebab Case");
table.addRowsForInputs(inputs, this::toCamelCase, this::toSnakeCase, this::toKebabCase);
Approvals.verify(table);
which will produce:
Input | Camel Case | Snake Case | Kebab Case |
---|---|---|---|
verify json | verifyJson | verify_json | verify-json |
verify all | verifyAll | verify_all | verify-all |
verify parameters | verifyParameters | verify_parameters | verify-parameters |
verify as json | verifyAsJson | verify_as_json | verify-as-json |