Skip to content

Latest commit

 

History

History
111 lines (86 loc) · 4.73 KB

test_combinations_of_inputs.md

File metadata and controls

111 lines (86 loc) · 4.73 KB

How to Test Combinations Inputs

Contents

What is Combination Testing

If you have a function isAwake(day, time) and you want to test it for multiple days & times. Combination Testing can be used to generate all combinations of provided inputs.

Input1
(Day)
Input2
(Time)
Output
(isAwake)
Sunday 7:00 No
Sunday 9:00 No
Sunday 11:00 Maybe
Monday 7:00 Maybe
Monday 9:00 Yes
Monday 11:00 Yes

If you wanted to test this matrix combination approvals can do it with a single line:

verify_all_combinations(is_awake, [["Monday", "Sunday"], ["7:00", "9:00", "11:00"]])

snippet source | anchor

When to use Combinations

You have a function that takes, for example, 3 parameters, and you want to test its behaviour with a bunch of different values for each of those parameters.

If you have only one parameter that you want to vary, check out How to Test a Variety of Values for One Input.

Steps

  1. Copy this starter text, and adjust for the number of inputs that you have.

inputs1 = ["input1.value1", "input1.value2"]
inputs2 = ["input2.value1", "input2.value2", "input2.value3"]
verify_all_combinations(lambda a, b: "placeholder", [inputs1, inputs2])

snippet source | anchor

  1. Modify each 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: it is the left hand side of the file that matters at this point: all combinations of your own input values should be listed:

args: ('input1.value1', 'input2.value1') => 'placeholder'
args: ('input1.value1', 'input2.value2') => 'placeholder'
args: ('input1.value1', 'input2.value3') => 'placeholder'
args: ('input1.value2', 'input2.value1') => 'placeholder'
args: ('input1.value2', 'input2.value2') => 'placeholder'
args: ('input1.value2', 'input2.value3') => 'placeholder'

snippet source | anchor

  1. Implement the body of your lambda
  2. Run it, and approve the output.

For advice on effective formatting, see Tips for Designing Strings. As you write out larger volumes of data in your approval files, experience has shown that the choice of layout of text in approval files can make a big difference to maintainability of tests, when failures occur.

Named Inputs

You can also use named inputs, which can make your tests more readable. Here is an example:

verify_all_combinations_with_labeled_input(
    self.func,
    arg1=(1, 3),
    arg2=(2, 4),
)

snippet source | anchor

which will produce the following output:

(arg1: 1, arg2: 2) => 4
(arg1: 1, arg2: 4) => 6
(arg1: 3, arg2: 2) => 6
(arg1: 3, arg2: 4) => 8

snippet source | anchor


Back to User Guide