Remove duplicate code using Data Driven Tests (DDT)
Many times, there are a number of data sets that we have to run the same tests on. And, to create a different test for each data set values is time-consuming and inefficient.
Data Driven Testing [1] overcomes this issue. Data-driven testing (DDT) is taking a test, parametrizing it and then running that test with varying data. This allows you to run the same test case with many varying inputs, therefore increasing coverage from a single test, reduces code duplication and can ease up error tracing as well.
DDT is a third party library needs to be installed separately and invoke the module when writing the tests. Several openstack projects [2] are using DDT for test optimization.
DDT generates the test names automatically which can be problematic to trace out for which test data failure occurred. To overcome this limitation we can pass descriptive name using annotate function as shown below:
@ddt.data(
def test_create_
pass
it generates following test names:
test_create_
test_create_
This will help to find out failure against particular test data.
Same is implemented in 'openstack/zaqar' [3].
[1] http://
[2] http://
[3] https:/
Blueprint information
- Status:
- Complete
- Approver:
- Matt Riedemann
- Priority:
- Undefined
- Drafter:
- Dinesh Bhor
- Direction:
- Needs approval
- Assignee:
- Dinesh Bhor
- Definition:
- Superseded
- Series goal:
- Proposed for ocata
- Implementation:
- Slow progress
- Milestone target:
- None
- Started by
- Dinesh Bhor
- Completed by
- Dinesh Bhor