Changing the interface requires updating the code that uses this interface. In this regard, the test code is no different from code other than it. Inevitably, the tests for this interface will need to change.
Often, when the interface changes, you find that "too many" tests are interrupted, i.e. tests for a significant part of unrelated functions turn out to be dependent on this interface. This may be a sign that your tests are too wide and need to be refactored. There are many possible ways that can happen, but here is an example that, I hope, shows a general idea, as well as a specific case.
For example, if the method of creating an Account object has been changed, and this requires updating all or most of your tests for your Order class, something is wrong. Most of your test order blocks probably don't care about how the account is made, so refactoring checks the following:
def test_add_item_to_order(self): acct = Account('Joe', 'Bloggs') shipping_addr = Address('123 Elm St', 'etc' 'etc') order = Order(acct, shipping_addr) item = OrderItem('Purple Widget') order.addItem(item) self.assertEquals([item], order.items)
:
def make_order(self): acct = Account('Joe', 'Bloggs') shipping_addr = Address('123 Elm St', 'etc' 'etc') return Order(acct, shipping_addr) def make_order_item(self): return OrderItem('Purple Widget') def test_add_item_to_order(self): order = self.make_order() item = self.make_order_item() order.addItem(item) self.assertEquals([item], order.items)
This particular template is a Creation Method .
The advantage is that your test methods for ordering are isolated from how accounts and addresses are created; if these interfaces change, you have only one place to change, and not every test that is used to use accounts and addresses.
In short: tests are also code, and like all code, sometimes they need refactoring.