Skip to content

DatabaseManager singleton makes testing difficult #295

@leesjensen

Description

@leesjensen

The global DatabaseManager class makes it difficult to do testing using dependency inversion.

  1. Properties are read from a file rather than providing them to the manager.
  2. The singleton pattern makes it difficult to load different databases for different tests or to create and delete a database for a test.
  3. It forces the same database to be used for both testing and development.
  4. It forces tests to use introspection to implemented desired behavior at runtime.
  5. It encourages the exposure of a dangerous endpoint (clear) in order to enable testing.

Most implementations are already passing a DataAccess object around and so there is little value in a DatabaseManager singleton. We should just initialize the DataAccess object with the desired DatabaseManager. Then a test could provide a mocked database version if desired, or set up and tear down a test database. You could get rid of the clear endpoint.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestrequirements:high changeThis code introduces a significant changes to the requirements for the projectrequirements:low changeThis code introduces a small change in requirements for the project

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions