0

The question is about the classic topic of different test doubles. I only have some naming problems about this code snippet:

@pytest.fixture(autouse=True)
def setup(self):
    class DummyModel:
        id = "model_id"
        changes = {}

        def has_changed(self):
            return False

        def collect_changes(self, *args, **kwargs):
            return {}

    class DummyModelWithoutChanges:
        id = "model_id"

    class DummyModelWithPartner(DummyModel):
        partner_id = "partner id"

    self.dummy_instance = DummyModel()
    self.dummy_instance_without_changes = DummyModelWithoutChanges()
    self.dummy_instance_with_partner = DummyModelWithPartner()

Is this DummyModel actually a Dummy or more like a StubModel? It has functions that only return burnt in values (could be just attributed at this point), but a test looking for a method on a test double sounds more than just a dummy (Which is supposed to be a placeholder)

Maybe this example is too rudimentary but I'm trying to get a clear picture of the different naming conventions while using Python.

I reckon Stubs are always compared to Mocks (which are smart, behavioral stubs), but not with Dummies or Fakes.

MattSom
  • 2,097
  • 5
  • 31
  • 53
  • 1
    A dummy is something that _doesn't_ get interacted with. That's a read-only collaborator; it's a stub. See e.g. https://tanzu.vmware.com/content/pivotal-engineering-journal/the-test-double-rule-of-thumb-2. – jonrsharpe Aug 13 '21 at 13:14
  • So even if we only have an attribute with a burnt in value, it is a Stub Class? Or just in the case of stubbed methods? – MattSom Aug 13 '21 at 16:27
  • Do you mean _baked_ in? If it's still read only, why would it make a big difference whether or not you're calling a method? – jonrsharpe Aug 13 '21 at 16:34
  • I see. One more question: what about test classes inherited from actual classes. like `class FakeModel(SQLAlchemy.Model)`. It is a real object like an integer, so should I call it simply something like `TestModel` instead? Only that it has no use in production (sound like a fake). – MattSom Aug 13 '21 at 18:14

0 Answers0