Pattern – data-driven tests
We briefly explored data-driven tests earlier. Data-driven tests reduce the amount of boilerplate test code by allowing us to write a single test execution flow and run it with different combinations of data.
The following is an example using the nose2 parameterization plugin that we looked at earlier in this book:
from nose2.tools.params import params
def given_a_series_of_prices(stock, prices):
timestamps = [datetime(2014, 2, 10), datetime(2014, 2, 11),
datetime(2014, 2, 12), datetime(2014, 2, 13)]
for timestamp, price in zip(timestamps, prices):
stock.update(timestamp, price)
@params(
([8, 10, 12], True),
([8, 12, 10], False),
([8, 10, 10], False)
)
def test_stock_trends(prices, expected_output):
goog = Stock("GOOG")
given_a_series_of_prices(goog, prices)
assert goog.is_increasing_trend() == expected_outputRunning tests like this requires the use of nose2. Is there a way to do something similar using...