Mockito Concepts: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 24: Line 24:
=Managed Test Double=
=Managed Test Double=
A [[Software Testing Concepts#Test_Double|test double]] managed by Mockito. It can be created either via the API with <code>[[#Mockito.mock.28.29|Mockito.mock(<object>)]]</code> or by annotating the field referencing the object in question with [[#@Mock|@Mock]].
A [[Software Testing Concepts#Test_Double|test double]] managed by Mockito. It can be created either via the API with <code>[[#Mockito.mock.28.29|Mockito.mock(<object>)]]</code> or by annotating the field referencing the object in question with [[#@Mock|@Mock]].
=Mockito Stub=
{{Internal|Mockito_Programming_Model#Implementing_Stub_Functionality|Mockito Programming Model &#124; Implementing Stub Functionality}}

Revision as of 16:52, 16 July 2021

Internal

Overview

The Mockito framework helps with the creation and management of external dependencies, and provides an API and annotations to create managed test doubles, most often mock objects. Mockito works by dynamically creating proxies that intercept invocation into the managed test double objects and reacting the way they were programmed - return pre-defined answers, throw exceptions, verifying the invocation, etc. when the invocations are sent into the managed test doubles.

MockitoJUnitRunner

Mockito.mock()

Programming Model | API

@Mock

Programming Model | Annotations

Can't Mock

  • Final classes
  • Final methods
  • Enums
  • Static methods
  • Private methods
  • hashCode() and equals() methods
  • Anonymous classes
  • Primitive types

PowerMock can mock these constructs.

Managed Test Double

A test double managed by Mockito. It can be created either via the API with Mockito.mock(<object>) or by annotating the field referencing the object in question with @Mock.

Mockito Stub

Mockito Programming Model | Implementing Stub Functionality