awesome-repositories.com
博客
MCP
awesome-repositories.com

通过 AI 驱动的搜索,发现最优秀的开源仓库。

探索精选搜索开源替代品自托管软件博客网站地图
项目关于排名机制媒体报道MCP 服务器
法律隐私政策服务条款
© 2026 Bringes Technology SRL·VAT RO45896025·hello@awesome-repositories.com
·
mockk avatar

mockk/mockk

0
View on GitHub↗
5,747 星标·410 分支·Kotlin·Apache-2.0·4 次浏览mockk.io↗

Mockk

MockK is a Kotlin test double framework that creates mocks, spies, and relaxed mocks for unit testing, with support for final classes, static methods, and coroutines. It functions as a bytecode instrumentation library that modifies compiled class files at load time to intercept constructors, final methods, and static functions without source changes, and also provides dedicated libraries for constructor mocking and coroutine mocking. The framework is designed specifically for Kotlin, handling Kotlin-specific constructs like extension functions, singletons, and suspend functions.

MockK distinguishes itself through comprehensive test double creation and verification capabilities, including stubbing, argument capture, call count and order verification, and support for various Kotlin constructs. It offers flexible argument matching with custom matchers, chained call stubbing, and dynamic answer provision. The framework supports both strict and relaxed mock creation, where relaxed mocks return default values for unstubbed calls, and provides spy wrapping that allows selected methods to be stubbed while others execute their original implementation. MockK also includes Android instrumented test support, using DexOpener to make final classes subclassable on pre-Android P devices and inline instrumentation on P+.

The framework provides extensive verification features including timeout-based verification for concurrent code, full call verification, unnecessary stub detection, and call recording exclusion. It supports mocking of private members, enum constants, object instances, and singleton objects, along with initialization block suppression and superclass call suppression. MockK offers annotation-based mock initialization with JUnit rule lifecycle management, automatic mock injection, and global configuration defaults that can be set project-wide through configuration files or system properties.

Features

  • Test Double Libraries - Creates a test double for any class and lets you stub its methods to return specific values.
  • Kotlin Unit Testing - Creates lightweight mock objects to isolate and verify behavior of Kotlin code during unit tests.
  • Bytecode and Instrumentation - Modifies compiled class files at load time to intercept constructors, final methods, and static functions without source changes.
  • Mock Argument Capturers - Records actual arguments passed to stubbed methods for later inspection or assertion in tests.
  • Mocking Libraries - Creates test doubles for Kotlin classes, including final classes, static methods, and coroutines, without modifying production code.
  • Return Value Configurations - Defines what a mocked method should return when called with specific arguments.
  • Bytecode Instrumentation Agents - Modifies compiled class files at load time to intercept constructors, final methods, and static functions without source changes.
  • Suspend Function Stubbings - Stubs and verifies suspend functions and coroutine-heavy code, enabling controlled asynchronous behavior in tests.
  • Load-Time Class Transformations - Modifies compiled class files during class loading to intercept constructors, final methods, and static functions without source changes.
  • Lambda Argument Capturers - Captures lambda arguments passed to mocked functions for post-execution inspection during tests.
  • Extension and Constructor Function Mockings - Intercepts constructor calls and stubs suspend functions to test code that creates objects or uses coroutines internally.
  • Static Function Mockings - Replaces static and top-level Kotlin functions with mocks for stubbing and verification in tests.
  • Static Method Mockings - Replaces static and extension function calls with controlled behavior for test isolation.
  • Top-Level Function Stubs - Replaces standalone Kotlin functions with mocks for testing code that calls them.
  • Lambda Argument Captures for Mocks - Captures lambda arguments and mocks suspend functions so coroutine-heavy code is testable without a real dispatcher.
  • Mock Call Order Verifications - Asserts that interactions with a mock happened in a specific sequence, or that no unexpected calls occurred.
  • Chained Call Answer Providers - Returns a nested mock or value when a chain of method calls is invoked on a mock.
  • Method Stubbings - Defines what a mock returns or does when a specific method is called, including chained calls and multiple answers.
  • Static or Top-Level Function Stubs - Replaces static methods and top-level functions with stubs for the duration of a test.
  • Method Invocation Verifications - Asserts that a mocked method was called a specific number of times, or within a minimum and maximum range.
  • Chained Call Stubbers - Stubs a sequence of property or method accesses on a mock, returning nested mocks for intermediate steps.
  • Kotlin Construct Mocks - Mocks Kotlin-specific constructs like objects, static methods, coroutines, and extension functions in Android instrumented tests.
  • Singleton Object Mocks - Replaces Kotlin singleton objects with mocks for the duration of a test, restoring originals afterward.
  • Singleton Object Replacements - Replaces Kotlin singleton objects with mocks for the duration of a test, restoring originals afterward.
  • Constructor Interceptors - Intercepts constructor calls to return mock instances, useful for testing code that creates objects internally.
  • Relaxed Mocks - Creates relaxed mocks that return default values for unstubbed calls, reducing test boilerplate.
  • Final Member Mocks - Overrides final and closed classes during tests, removing the usual restriction on subclassing them.
  • Static Member Mocks - Mocks final classes, object instances, and static methods using bytecode instrumentation to isolate tests from real implementations.
  • Unit Testing - Enables isolated unit testing by creating lightweight mock objects that simulate real dependencies.
  • Method Interception Spies - Wraps real objects so unstubbed methods execute original implementations while stubbed methods return configured values.
  • Suspend Function Interceptions - Intercepts Kotlin suspend function calls at the bytecode level to allow stubbing and verification of coroutine-based methods.
  • Test Double Frameworks - Creates mocks, spies, and relaxed mocks that support Kotlin-specific features like extension functions, constructors, and singletons.
  • Dynamic Mock Answer Providers - Returns computed or dynamic results from stubbed methods based on call arguments or internal state.
  • Mock Null Value Handlings - Handles null values in mocks by returning null or accepting null arguments for nullable type coverage.
  • Mock Lifecycle Scopes - Manages mock lifecycle within lexical scopes, automatically clearing interactions after scope exit.
  • Concurrent Operation Verifications - Waits up to a timeout for verification to pass, enabling testing of code running on other threads.
  • Test Lifecycle Rules - Uses a JUnit rule or extension to automatically initialize and clean up mocks per test class.
  • Private Member Stubs - Stubs and verifies private methods and properties on spies using dynamic call syntax.
  • Mock Argument Matchers - Uses matchers to specify acceptable argument values when stubbing or verifying, including wildcards and custom predicates.
  • Matcher Expressions - Writes concise expressions that match arguments by condition such as equality, type, or custom predicates.
  • Partial Argument Matchers - Specifies argument matchers for only some parameters of a call, leaving others to match any value automatically.
  • Mock Backing Field Accessors - Overrides the value stored in a property's backing field on a mock, bypassing getter and setter logic.
  • Call Recording Exclusions - Ignores specified method calls during exhaustive verification so they do not cause failures.
  • Concurrent Call Verifications - Waits for verification to pass within a timeout, enabling testing of asynchronous or multi-threaded code.
  • Exhaustive Call Verifications - Checks that every recorded call on a mock has been covered by a verification statement.
  • Sequenced Call Answer Providers - Supports returning a sequence of different values from a stubbed method across successive calls.
  • Property Backing Field Overrides - Reads or modifies the backing field of a property during stubbing or verification.
  • BDD Syntax Aliases - Writes test stubs and verifications using given/when/then syntax for behavior-driven development.
  • Mock State Resetting - Resets internal recording and stubbing state of mocks without removing their bytecode transformations.
  • Global Mock Restorations - Restores all mocked objects, statics, and constructors to their original state after test execution.
  • Array Type Mock Definitions - Stubs methods that accept or return arrays, handling array types correctly in mock definitions.
  • Annotation-Driven Mock Injections - Declares mocks, spies, and injected mocks with annotations and initializes them automatically in a setup method.
  • Mock Strictness Dispatchers - Creates mocks that require explicit behavior definitions for every call and fail on unexpected invocations.
  • Android Instrumented Mock Objects - Provides mock objects designed for Android instrumented test environments with platform-specific adaptation.
  • Initialization Block Suppressors - Suppresses the execution of class initialization blocks when creating mock objects to prevent side effects.
  • Instance-Level Mock Replacements - Replaces behavior on specific object instances at runtime to verify interactions on real objects.
  • Nested Mock Builders - Builds a tree of nested mocks in a single DSL block, defining behavior for deeply nested properties concisely.
  • Mock Restorations - Restores individual mocked classes, objects, or static methods back to their original implementations.
  • Android Final Class Mocks - Mocks final classes in Android instrumented tests using DexOpener on pre-P and inline instrumentation on P+.
  • Private Function Overrides - Overrides private method implementations on mocks to control internal behavior during tests.
  • Private Method Stubs - Stubs or verifies private methods on spies using dynamic call syntax for complete code isolation.
  • Custom Matchers - Provides a DSL for defining custom argument matchers using the match helper function or Matcher interface.
  • Vararg Method Stubbers - Stubs and verifies methods that accept variable-length argument lists.
  • Timeout-Based Verifications - Waits for verification to pass within a time limit, enabling testing of concurrent code.
  • 测试框架 - Mocking library for Kotlin.

Star 历史

mockk/mockk 的 Star 历史图表mockk/mockk 的 Star 历史图表

AI 搜索

探索更多 awesome 仓库

用简单的语言描述您的需求 —— AI 将根据相关性为您从数千个精选开源项目中进行排序。

Start searching with AI

Mockk 的开源替代方案

相似的开源项目,按与 Mockk 的功能重合度排序。
  • powermock/powermockpowermock 的头像

    powermock/powermock

    4,174在 GitHub 上查看↗

    Powermock is a Java mocking framework and unit testing tool that uses bytecode manipulation to mock static methods, final classes, and private constructors. It includes a Java agent instrumentation tool and a reflection-based testing utility to bypass encapsulation and modify class behavior at runtime. The project distinguishes itself by providing the ability to intercept the instantiation of objects via the new keyword and simulate the behavior of core Java system classes and native methods. It can override final modifiers on classes and methods and bypass signature restrictions for classes

    Java
    在 GitHub 上查看↗4,174
  • devlooped/moqdevlooped 的头像

    devlooped/moq

    6,389在 GitHub 上查看↗

    Moq is a .NET mocking framework and C# library used to create simulated objects and interfaces. Its primary purpose is to isolate code from external dependencies during unit testing by providing a system for interface simulation and behavioral testing. The framework distinguishes itself through the use of functional specification queries and LINQ-based querying to create declarative mocks. It supports the simulation of complex scenarios, including the automatic generation of recursive mock hierarchies, the implementation of multiple interfaces within a single mock instance, and the ability to

    C#
    在 GitHub 上查看↗6,389
  • sapegin/jest-cheat-sheetsapegin 的头像

    sapegin/jest-cheat-sheet

    5,428在 GitHub 上查看↗

    This project is a comprehensive reference guide and cheat sheet for the Jest testing framework. It provides technical documentation and syntax examples for writing JavaScript unit tests, focusing on assertions, mocking strategies, and test suite configuration. The resource details specific methods for dependency isolation and mocking, including the use of fake timers, module-level substitutions, and function call verification. It also covers specialized workflows such as snapshot testing to detect regressions via serialized output comparisons. The guide further addresses asynchronous test pa

    cheatsheetjesttesting
    在 GitHub 上查看↗5,428
  • codeception/codeceptionCodeception 的头像

    Codeception/Codeception

    4,855在 GitHub 上查看↗

    Codeception is a full-stack testing framework for PHP applications that provides a unified interface for unit, functional, and acceptance testing. It serves as a tool for automating real desktop and mobile browsers via the WebDriver protocol and acts as a client for testing REST and SOAP APIs. The framework is distinguished by its support for Behavior-Driven Development, allowing users to write human-readable test specifications in Gherkin language to align technical tests with business requirements. It implements actor-based action mapping to connect these natural language steps to executabl

    PHP
    在 GitHub 上查看↗4,855
查看 Mockk 的所有 30 个替代方案→

常见问题解答

mockk/mockk 是做什么的?

MockK is a Kotlin test double framework that creates mocks, spies, and relaxed mocks for unit testing, with support for final classes, static methods, and coroutines. It functions as a bytecode instrumentation library that modifies compiled class files at load time to intercept constructors, final methods, and static functions without source changes, and also provides dedicated libraries for constructor mocking and coroutine mocking. The framework is designed specifically…

mockk/mockk 的主要功能有哪些?

mockk/mockk 的主要功能包括:Test Double Libraries, Kotlin Unit Testing, Bytecode and Instrumentation, Mock Argument Capturers, Mocking Libraries, Return Value Configurations, Bytecode Instrumentation Agents, Suspend Function Stubbings。

mockk/mockk 有哪些开源替代品?

mockk/mockk 的开源替代品包括: powermock/powermock — Powermock is a Java mocking framework and unit testing tool that uses bytecode manipulation to mock static methods,… devlooped/moq — Moq is a .NET mocking framework and C# library used to create simulated objects and interfaces. Its primary purpose is… sapegin/jest-cheat-sheet — This project is a comprehensive reference guide and cheat sheet for the Jest testing framework. It provides technical… codeception/codeception — Codeception is a full-stack testing framework for PHP applications that provides a unified interface for unit,… golang/mock — GoMock is a mocking framework for the Go programming language. sebastianbergmann/phpunit-mock-objects — This project is a mocking framework and library designed for creating simulated objects to isolate code and verify…