Skip to content

Do not unmock all mocks after every test function, but after the entire test class only. Clear mocks after every test function. #820

@erikhuizinga

Description

@erikhuizinga

Prerequisites

Please answer the following questions for yourself before submitting an issue.

  • I am running the latest version
  • I checked the documentation and found no answer
  • I checked to make sure that this issue has not already been filed

Expected Behavior

The provided JUnit 4 rule /. JUnit 5 extension efficiently run before/after test functions and classes.

Current Behavior

The provided JUnit 4 rule / JUnits 5 extension unmock after every test.

Context

In general, mocking can be expensive. Do not unmock unless the test class is completely done. Prefer clearing mocks instead of unmocking between test class functions.

The suggestion is to do the following for both the JUnit 4 rule and the JUnit 5 extension:

  • Before tests, init annotations
  • After every test function, clear all mocks.
  • After all test functions (after a test class), unmock all mocks.

V

  • MockK version: 1.12.4

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions