Mocking Classes in Kotlin with Mockative

Kristian Degn Abrahamsen, Jacopo Mauro*

*Corresponding author for this work

Research output: Chapter in Book/Report/Conference proceedingArticle in proceedingsResearchpeer-review

Abstract

Unit testing is instrumental in enhancing code quality, documenting system behavior, and preventing regressions in contemporary software development. One of the current limitations of the most popular existing unit-testing frameworks for the Kotlin language (e.g., MockK and Mockito) is that they are inherently tied to the Java Virtual Machine (JVM), restricting their use to JVM-compatible environments. To overcome this limitation, in this paper we present an extended version of Mockative, a Kotlin-specific mocking framework designed to operate across multiple platforms beyond the JVM. While originally Mockative was limited to interface mocking, we have enhanced it to support class mocking and spying through the utilization of Kotlin Symbol Processing (KSP) and KotlinPoet libraries. We show that Mockative is a viable alternative to traditional JVM-bound frameworks, particularly in Kotlin/Native environments. Our extension can mock simple classes up to four times faster than MockK and Mockito, although it exhibits a marginal performance decline in scenarios involving classes with extensive method definitions.

Original languageEnglish
Title of host publicationSoftware Engineering and Advanced Applications : Proceedings of 51st Euromicro Conference, SEAA 2025
EditorsDavide Taibi, Darja Smite
PublisherSpringer Science+Business Media
Publication date2026
Pages23-31
ISBN (Print)978-3-032-04199-9
ISBN (Electronic)978-3-032-04200-2
DOIs
Publication statusE-pub ahead of print - 9. Sept 2025
Event51st Euromicro Conference on Software Engineering and Advanced Applications, SEAA 2025 - Salerno, Italy
Duration: 10. Sept 202512. Sept 2025

Conference

Conference51st Euromicro Conference on Software Engineering and Advanced Applications, SEAA 2025
Country/TerritoryItaly
CitySalerno
Period10/09/202512/09/2025
SponsorUNIVERSITA DEGLI STUDI DI SALERNO, DIPARTIMENTO DI INFORMATICA
SeriesLecture Notes in Computer Science
Volume16082 LNCS
ISSN0302-9743

Keywords

  • Kotlin
  • Mock
  • Unit Testing

Fingerprint

Dive into the research topics of 'Mocking Classes in Kotlin with Mockative'. Together they form a unique fingerprint.

Cite this