Skip to content

Use multiplatform mocking library for tests #5420

Open
@westnordost

Description

For mocking unit tests, we are currently using the Java library org.mockito:mockito.

In order that the tests for platform-independent application logic can be executed on any supported platform, mockito needs to be replaced as a test dependency.

Mocking library requirements

  • multiplatform support for at least Java/Android and iOS

  • stable, well-tested and ideally (semi-)official / well-maintained

  • support all features of Mockito we are using now

It is possible that when migrating, a bit more effort is necessary because as far as I know, Mockito uses Java reflection to create the mocks, which is a Java specific language feature. In other words, it may not be possible to mock non-interfaces.

Three Kotlin Multiplatform libraries for mocking are known to me, with a few comments from a short look at them, ordered by popularity on github:

Mockative

  • seems well maintained
  • good documentation
  • has a guide how to migrate from Mockito to Mockative and apparently also a similar API to Mockito

MocKMP

  • seems well maintained
  • good documentation
  • backed by a company (Deezer)

MockingBird

  • seems well maintained
  • from a quick glance, API seems to be a bit inconvenient
  • oldest library, i.e. started in 2021, the others in 2022

Metadata

Assignees

Labels

iOSnecessary for iOS port

Type

No type

Projects

  • Status

    In Progress

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions