When we want to test SUT, we usually want to test with different set of data. It is not ideal to create one test function for one set of input data. This is where data driven tests are helpful.

Consider the same example function that adds two numbers

```
function add(a, b):
return a+b
```

To be thorough, we need to test this function with few different set of data including but not limited to negative numbers, positive numbers and zeros.

Although, it will be descriptive and easy to follow when we have one test test function per input data, it requires more development and maintenance effort.

Better solution is to create one test function that we can run with different set of data. This is what we call data driven tests.

An example of data driven test would look like this

```
type DataTest:
input1
input2
result
function test_add():
// arrange
tests = [
[input1: 1, input2: 2, result: 3],
[input1: -1, input2: -1, result: 0],
[input1: 1, input2: -2, result: -1],
]
// act
loop test of tests:
result = add(test.input1, test.input2)
// assert
areEqual(test.result, result)
```

The actual implementation of data driven test will be different based on the language and the framework used.

© 2014 - 2019 Kodebot Limited. All Rights Reserved.

All content on this website is licensed under the
(CC
BY-SA 3.0)
Creative Commons Attribution-ShareAlike 3.0 Unported License. All source code published here is
licensed
under the
MIT License unless explicitly stated otherwise. The
content is
provided for
educational and informational purposes only without any warranties, guarantees or conditions, of any kind,
and
may not be accurate,
up to date or complete. Any use or reliance on any content or materials published, mentioned or linked here
is
at your own risk and
the Kodebot Limited and author/authors accept no liability or responsibility for.