Skip to content

Throw a warning when mocking classes that should not be mocked #1304

@Raibaz

Description

@Raibaz

There are a few classes that it is generally a bad idea to mock: trying to mock them is usually a code smell indicating that a test is not testing the correct part of the application, and mocking them usually leads to problems.

Some of these are:

  • System
  • Collections (particularly HashMap)
  • Data classes, and in general value objects
  • Classes that deal with I/O, like File or Path (you should be wrapping them in a layer that only deals with I/O rather than mixing it with business logic)

Mockk should at least log a warning when trying to mock one of these classes, but ideally it should also have a configuration flag that disables mocking them altogether and has it throw an exception when a user tries to.

We could maybe even make the list of non-mockable classes configurable.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions