mockito/mockito-scala
55.5
Adequate · 6 November 2026
11.2k
lines of production code
Scala
primary language
4
measurements over time
What this system is
This system is a Scala library that extends the Mockito mocking framework to provide idiomatic, type-safe testing capabilities for the Scala ecosystem. It supports multiple Scala versions (2.12, 2.13, and 3) by leveraging compile-time macros and reflection to handle language-specific features such as value classes, by-name parameters, and varargs. The library offers a fluent DSL for stubbing and verification, along with specialized integrations for functional programming libraries like Cats and Scalaz, and testing frameworks including ScalaTest and Specs2.
How it got here
2018 — idiomatic Scala API and build migration
11 changes.
The project established its foundational build infrastructure, migrating to a multi-module Gradle and SBT setup with support for Scala 2 and 3. Significant development focused on creating a new idiomatic mocking API, featuring natural language syntax for stubbing and verification, alongside specialized handling for Scala-specific features like value classes and by-name parameters.
2019 — Scala ecosystem integration expansion
19 changes.
This period focused on deepening Mockito's support for the Scala ecosystem by introducing idiomatic integration modules for ScalaTest, specs2, Cats, and Scalaz. The work involved implementing Scala-specific invocation handling, enhancing vararg and default value behaviors, and adding comprehensive test coverage to ensure compatibility with Scala's unique type system and testing conventions.
2020–2026 — Scala 3 migration and macro support
9 changes.
The project implemented comprehensive Scala 3 support by introducing idiomatic macro-based DSLs and replacing runtime reflection with compile-time metadata for mock creation. This period also involved isolating Scala 2-specific logic, adding Cats typeclass instances for argument matchers, and ensuring compatibility with Scala 2.13+ features and testing frameworks.
Features
Add Cats typeclass instances for ArgumentMatcher
Users can now leverage Cats typeclasses for Mockito's ArgumentMatcher. The new \ArgumentMatcherInstances\ trait provides \ContravariantMonoidal\ and \MonoidK\ instances, enabling functional composition of matchers using Cats abstractions such as \contramap\, \product\, and \combineK\. This allows for more expressive and composable argument matching within Scala projects using the Cats library.
cats/src/main/scala/org/mockito/cats/instances · high confidence
Add Scalaz integration for mocking effect types
Users can now mock methods that return Scalaz effect types (such as \F\[T\]\ or \F\[G\[T\]\]\) using idiomatic syntax like \whenF\, \doReturnF\, \doFailWith\, and \doAnswerF\. This new module provides runtime support and equality conversions (\EqToEquality\) to seamlessly integrate Scalaz's \Applicative\ and \MonadError\ constraints with Mockito's stubbing API.
scalaz/src/main · high confidence
Add specs2 integration module
Adds a new specs2 module that provides idiomatic integration between Mockito and the specs2 testing framework. This includes support for specs2 matchers in argument matching, verification syntax (such as 'was', 'were', 'there'), and stubbing helpers, allowing users to write Mockito tests using specs2's DSL.
specs2/src/main/scala · high confidence
Added Scala 3 compatibility layer for specs2 integration
Users can now use Mockito with specs2 in Scala 3 projects. A new compatibility module provides Scala 3-specific implementations for verification methods like \was\, \were\, and \got\, as well as the \andThen\ extension on MatchResult, ensuring these features work correctly with Scala 3's inline macros and extension syntax.
specs2/src/main/scala-3 · high confidence
Idiomatic Cats syntax for mocking effect types
Adds idiomatic syntax support for the Cats library, allowing users to mock methods that return effect types (e.g., \F\[T\]\) using familiar Mockito-style methods like \whenF\, \doReturnF\, \doAnswerF\, and \willBe answeredF\. This integration leverages Cats \Applicative\ and \ApplicativeError\ type classes to handle pure values and errors within effects, and integrates Cats \Eq\ with Scalactic \Equality\ to ensure correct argument matching for effect-returning mocks.
cats/src/main/scala/org/mockito/cats · high confidence
Initial project scaffolding and configuration
The repository is initialized with essential build and configuration files, including a \.gitignore\ to exclude build artifacts and IDE files, \.sbtopts\ to configure SBT memory limits, and \.scalafmt.conf\ to enforce code formatting (version 3.11.5, 180-column width). It also adds a \LICENSE\ (MIT), a \README.md\ documenting the Mockito Scala library and its dependencies, and Gradle wrapper scripts (\gradlew\, \gradlew.bat\) to support Gradle-based builds.
(repo-wide) · high confidence
Introduces Scala-native stubbing abstractions and value class support
This change adds new Scala-specific stubbing components in the \org.mockito.stubbing\ package, including \DefaultAnswer\ and \ScalaAnswer\ traits, to provide idiomatic ways to define mock behaviors. It also introduces \ScalaBaseStubbing\, which implements \\_thenAnswer\ methods supporting functions with up to 15 parameters and integrates \ValueClassExtractor\ and \ValueClassWrapper\ to properly handle Scala value classes in stubbing scenarios.
common/src/main/scala/org/mockito/stubbing · high confidence
Introduction of ScalaInvocation for Scala-specific mock handling
A new ScalaInvocation class has been added to handle invocations within the Scala ecosystem, extending the standard Invocation interface with VerificationAwareInvocation support. This implementation integrates with Scala-specific libraries, specifically using Scalactic's Prettifier for argument formatting and EqTo for argument matching, ensuring that Scala mocks behave correctly with Scala's equality and pretty-printing conventions.
common/src/main/scala/org/mockito/internal/invocation · high confidence
New Scala-specific argument matchers in the common matchers module
The \common/src/main/scala/org/mockito/matchers\ module now provides a suite of Scala-native argument matchers to improve type safety and idiomatic usage. This includes \AnyMatchers\ for Scala collection types (List, Seq, Iterable, Set, Map) to avoid Java/Scala collection mismatches, \NumericMatchers\ for natural comparison operators (\\>\, \\>=\, \\<\, \\<=\, \=\~\) on numeric types, and \StringThatMatchers\ for string operations (\matches\, \startsWith\, \contains\, \endsWith\). Additionally, \EqMatchers\ now leverages Scalactic's \Equality\ for customizable value comparison in \eqTo\, and \ThatMatchers\ introduces \argMatching\ for partial function matching and primitive-specific matchers to reduce implicit conversion overhead.
common/src/main/scala/org/mockito/matchers · high confidence
New idiomatic stubbing and matcher APIs for Scala 2 and 3
This release introduces a new idiomatic API for stubbing and verification, available for both Scala 2 and Scala 3. In the core module, \IdiomaticMockitoBase\ provides macro-based operations like \willBe(returnedF).by(...)\ and \willBe(answeredF).by(...)\, allowing users to stub methods with a more natural, fluent syntax. The \cats\ module extends this idiomatic style to \cats-effect\ types (\F\[T\]\ and \F\[G\[T\]\]\), enabling direct stubbing of effect-returning methods. Additionally, the \common\ module adds new argument matchers (\AllOf\, \EqTo\, \ProductOf\, \Transformed\) and a \ReturnsSmartNulls\ default answer to improve test expressiveness and safety.
repository · high confidence
New idiomatic stubbing and verification DSL for Scala
The core module now provides a new idiomatic API for mocking, allowing users to write stubs and verifications using natural language syntax. Stubbing is supported via postfix operators like \returns\, \throws\, and \answers\, as well as prefix expressions like \value willBe returned by method\. Verification is available through postfix syntax such as \was called\ and \wasNever called\, alongside a new prefix \expect\ DSL for defining call counts (e.g., \expect.one call\). This API is implemented with version-specific macro files for Scala 2 and Scala 3 to ensure type safety and better error messages, and is exposed through the \IdiomaticMockito\ trait.
core · high confidence
Scala 3 idiomatic macro support added alongside Scala 2 implementation
The macro module now provides idiomatic stubbing, verification, and expectation DSLs for both Scala 2 and Scala 3. Scala 2 sources are organized under \scala-2/\ and include \WhenMacro\, \DoSomethingMacro\, \VerifyMacro\, \ExpectMacro\, and \Specs2VerifyMacro\. Scala 3 sources under \scala-3/\ implement equivalent functionality using the new \scala.quoted\ API, including \DoSomethingMacro\, \ExpectMacro\, \VerifyMacro\, and shared \Utils\. Runtime classes like \Captor\ and \DefaultValueProvider\ are extracted to shared files to support both versions.
macro · high confidence
Behavioural changes
Added Scala 2.13+ specific stubbing and utility implementations
New source files have been added to the Scala 2.13+ specific source directory to support version-specific features. The \ReturnsEmptyValues\ object now provides a comprehensive map of Scala collection types (such as \List\, \Set\, \Vector\, \Try\, and \Future\) to their respective empty values, enabling more accurate auto-stubbing behavior for mocks returning these types. Additionally, a new \handler\ package object introduces an \unwrapVarargs\ utility function that specifically handles \scala.collection.immutable.ArraySeq\ instances, ensuring varargs are correctly expanded when passed to mocked methods.
common/src/main/scala-2.13+ · high confidence
Enhanced Scala 2.12 vararg handling and expanded default return values
This update improves how Mockito handles vararg arguments in Scala 2.12 by introducing a new \unwrapVarargs\ utility that correctly flattens mutable wrapped arrays, ensuring transparent and consistent vararg support. Additionally, the \ReturnsEmptyValues\ default answer is expanded to provide sensible empty defaults for a broader range of Scala collection types (such as \Vector\, \Stream\, \ListBuffer\, and \mutable.Seq/Set\) and numeric types (\BigDecimal\, \BigInt\), reducing the need for manual stubbing in tests.
common/src/main/scala-2.12 · high confidence
Improved support for Scala value classes and by-name/vararg parameters
Mockito now correctly handles Scala value classes (AnyVal) in mock return values and arguments, resolving previous issues where value classes could not be used in the idiomatic API. Additionally, the library now accurately detects and processes by-name parameters and varargs at compile time, ensuring that mocks behave correctly with these parameter types. This change includes new macro implementations for both Scala 2 and Scala 3 to extract and wrap value classes, and a runtime cache to store method metadata for accurate reflection-based mocking.
macro-common · high confidence
New Scala-specific mock handling infrastructure
This change introduces a new set of handler classes in the \common\ module to better support Scala-specific language features. \ScalaMockHandler\ now processes invocations by unwrapping arguments to handle lazy evaluation (by-name parameters) and varargs more robustly, using \EqTo\ matchers for proper argument comparison. \ScalaNullResultGuardian\ ensures that primitive return types and value classes return appropriate default values instead of null, preventing runtime errors. Additionally, \ThreadAwareMockHandler\ makes object mocking thread-safe by delegating to the real implementation for invocations from threads other than the one that created the mock.
common/src/main/scala/org/mockito/internal/handler · high confidence
New ScalaTest integration traits for mock session management and automatic reset
The ScalaTest module now includes new traits to improve mock lifecycle management. \MockitoSessionFixture\ and \MockitoSessionAsyncFixture\ automatically manage the Mockito session, ensuring that mocking is finished and any uncaught throwables are handled correctly during test execution. Additionally, \ResetMocksAfterEachTest\ and \ResetMocksAfterEachAsyncTest\ provide automatic reset of all mocks after each test runs, preventing state leakage between tests. These traits replace the older \IdiomaticMockitoFixture\ and integrate with the existing \IdiomaticMockito\ and \MockitoSugar\ traits.
scalatest/src/main · high confidence
Refactored idiomatic API and added support for value classes
The idiomatic API has been revised to improve usability and correctness, specifically adding support for returning value classes from answers and fixing issues where lazy arguments were evaluated twice. The \MockCreatorRuntime\ now uses \ClassTag\ instead of \TypeTag\ to support mocking parametrized classes and type aliases, while \JavaReflectionUtils\ has been updated to handle final field modification across different Java versions (including Java 13+). Additionally, the API now integrates with Scalactic for prettifying arguments in invocations and ensures that \verifyNoMoreInteractions\ fails if a non-mock is passed.
common/src/main/scala/org/mockito · high confidence
Scala 2-specific reflection utilities and mock creation logic are now isolated in the scala-2 source directory
The Scala 2-specific implementation details for creating mocks and handling reflection have been moved from shared runtime code into the \common/src/main/scala-2\ directory. This change introduces \MockCreator.scala\, which provides Scala-specific \mock\ and \spy\ methods that leverage \WeakTypeTag\ to support generic type parameters and correctly handle default arguments, and \ReflectionUtils.scala\, which contains Scala 2-specific reflection helpers for resolving return types, identifying value classes, and detecting extra interfaces from refined types. This separation ensures that Scala 2-specific dependencies on \scala.reflect\ do not impact other Scala versions or the core runtime.
common/src/main/scala-2 · high confidence
Scala 3 mock creation now uses compile-time metadata for accurate method handling
The Scala 3 implementation of mock creation has been rewritten to use inline macros and a compile-time metadata cache instead of runtime reflection. This ensures that by-name parameters, varargs, and return types are correctly identified at compile time, preventing silent failures when stubbing methods with these signatures. Users must ensure that any helper methods wrapping \mock\[T\]\ or \spy\[T\]\ are also marked \inline\ to preserve this metadata; otherwise, argument unwrapping and return-type classification may fail.
common/src/main/scala-3 · high confidence
Support for stubbing checked exceptions in Scala mocks
Users can now stub methods that throw checked exceptions in Scala without encountering verification errors. Because Scala methods do not declare throws signatures, the previous Java-centric validation logic incorrectly prevented stubbing. This change introduces a Scala-specific exception handler that bypasses the signature check, allowing any exception to be stubbed on Scala mocks.
common/src/main/scala/org/mockito/internal/stubbing · high confidence
Test coverage
Added Mockito inline mock maker configuration for ScalaTest module; Added Scala 2.13+ specific test coverage for scalatest integration; Added Scala 3-specific tests for mock metadata and argument matchers; Added ScalaTest integration test suite for Mockito-Scala; Added ScalaTest integration tests for Scala 2.12; Added ScalaTest-based unit tests for ArgCaptor; Added ScalaTest-based unit tests for argument matchers; Added specs2 integration tests for Mockito Scala; Added test coverage for Scalaz integration; Added test coverage for idiomatic Cats syntax and applicative stubbing; Added test model classes for varargs and static method testing; Added tests for DefaultAnswer behavior in ScalaTest module; Added tests for ReturnsEmptyValues default answer behavior; Added tests for ScalaTest integration traits; Added tests for cats typeclass instances for ArgumentMatcher.
Dependencies
Initial project dependency and build configuration
The project now defines its build structure using a centralized dependency file (project/Dependencies.scala) and standard Sbt configuration files. This setup pins the build tool to Sbt 1.13.0, includes the sbt-scalafmt 2.6.2 plugin for code formatting, and declares specific versions for core testing and library dependencies, including Mockito 5.24.0, ScalaTest 3.2.20, Specs2 4.23.0, Cats 2.13.0, and Scalaz 7.3.9.
project · high confidence
Migrate build infrastructure to Gradle and SBT with multi-module support
The project has replaced its previous build system with a new Gradle and SBT configuration, introducing a multi-module structure that includes core, common, macro, scalatest, specs2, cats, and scalaz modules. This change enables cross-compilation for Scala 2.12, 2.13, and 3.3.8, and integrates Shipkit plugins for automated versioning, changelog generation, and GitHub releases, alongside Nexus publishing support for Maven Central.
(dependencies) · high confidence
Upgrade Gradle wrapper to version 8.10.2
The project's Gradle wrapper has been updated to use Gradle 8.10.2. This ensures that builds are executed with a consistent, modern version of the Gradle build tool, improving reliability and potentially enabling newer Gradle features for the build process.
gradle · high confidence
Written by cca.canine.dev from the codebase's own history, inside the signed delivery this page is composed from.
How this codebase got here
Score
- CAI 58 → 55 (-2.4)
- Rubric changed (rubric-2026.10.5 → rubric-2026.11.2) — scores are not directly comparable.
Lenses
- Code Health 60 → 60 (+0.0)
- Architecture 92 → 90 (-1.4)
- Maturity 49 → 47 (-2.8)
- Readiness 60 → 60 (+0.0)
- Security 80 → 67 (-13.3)
Resolved (1)
- Off-boarding risk: anonymized user #1
New (1)
- Off-boarding risk: anonymized user #1
Architecture
- Unchanged — 0 containers · 1 contexts · 0 edges
Written by cca.canine.dev from the codebase's own history, inside the signed delivery this page is composed from.
Survey your own repository
mockito/mockito-scala was measured the same way every project in this corpus was: the same rubric, at a pinned commit, with the result published in full. Point a surveyor at a repository you know and see whether you agree with it.
About this page
- The score is its most recent published measurement, taken on 6 November 2026 at a pinned commit. It is not a live figure and does not change until the project is measured again.
- Measured at commit 3d3203e610cf38ae07ee06fa91740faaf80aa46a — the exact code this score is about.
- Scored under rubric-2026.11.2 — the same rubric and the same method as every other entry in this index.
- Measured by Canine Code Analyzer (cca.canine.dev) using cca measure-2026.11.3+preprod-60d1b390edf0.