Skip to content

Latest commit

 

History

History
84 lines (60 loc) · 3.21 KB

TestAVarietyOfValues.md

File metadata and controls

84 lines (60 loc) · 3.21 KB

How to Test a Variety of Values for One Input

Contents

When to use Approvals::verifyAll()

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.

Steps

  1. Copy this starter text.

String[] inputs = {"input.value1", "input.value2"};
Approvals.verifyAll("TITLE", inputs, s -> "placeholder " + s);

snippet source | anchor

  1. Modify the input container for your chosen values.
  2. 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

snippet source | anchor

  1. Replace the "placeholder" with a call to the functionality that you want to test.
  2. Change the TITLE to something meaningful
  3. Run it, and approve the output.

Tables

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);

snippet source | anchor

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

Back to User Guide