Skip to content

Add docs about DI and mocking for tests  #11

@craigfowler

Description

@craigfowler

One thing that comes up when using specs is how to test them and how to test things which consume them. What this is really about is the consumption of specification objects. Whether they're consumed as interfaces or concrete classes, and the consequences of this for testing.

There are a few ways:

  • Write one-line interfaces for each spec
    • Then the dev just mocks the interface as usual
  • Use virtual members which can be overridden
    • No need for an extra interface, and the dev can mock an object with virtual members
  • Write and use a service locator
    • Anti-pattern but it would work to provide specs as interfaces

These techniques should be documented.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions