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_
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:
- Started
- Approver:
- Nikhil Komawar
- Priority:
- Undefined
- Drafter:
- Bhagyashri Shewale
- Direction:
- Needs approval
- Assignee:
- Bhagyashri Shewale
- Definition:
- Pending Approval
- Series goal:
- None
- Implementation:
- Slow progress
- Milestone target:
- None
- Started by
- Bhagyashri Shewale
- Completed by
Related branches
Related bugs
Sprints
Whiteboard
[2016-07-27 nikhil]
Hi Bhagyashri, drafting BP is not sufficient. You'd keep this as a placeholder and then file a spec for a full discussion. See more on: https:/