Skip to content
CAI
Software that uses CAICheck a score

mockito/mockito-scala

63.1

Adequate · 20 September 2026

11.2k

lines of production code

Scala

primary language

1

measurement over time

CAI band scale
CAI lens gauges

What this system is

This system is a Scala-specific extension for Mockito that provides idiomatic mocking, stubbing, and verification APIs tailored for the Scala language. It supports Scala 2.12, 2.13, and 3, leveraging macros and compile-time metadata to handle Scala-specific features like value classes, by-name parameters, and varargs. The library integrates with major testing frameworks such as ScalaTest and Specs2, and offers specialized modules for effect types in Cats and Scalaz.

How it got here

2018 — idiomatic Scala DSL and build migration

11 changes.

The project established its foundational build infrastructure, migrating to a multi-module Gradle and SBT setup with cross-compilation support. It then introduced a comprehensive idiomatic Scala DSL for mocking, featuring macro-based syntax, Scala-native argument matchers, and robust handling of value classes and by-name parameters.

2019 — Scala ecosystem integration expansion

19 changes.

This period focused on expanding Mockito's support for the Scala ecosystem by introducing dedicated integration modules for Scalatest, specs2, Cats, and Scalaz. The work involved implementing idiomatic syntax for mocking effect types and enhancing core Scala-specific behaviors, such as vararg handling and default return values. Comprehensive test suites were added to verify these new features and ensure compatibility with Scala 2.12.

2020–2026 — Scala 3 migration and integration

9 changes.

This period focused on implementing native Scala 3 support through compile-time macros for DSLs and mock creation, replacing runtime reflection. It also expanded ecosystem compatibility by adding Cats typeclass instances and specs2 integration, while isolating Scala 2-specific logic to ensure clean cross-version support.

Features

Add Cats typeclass instances for ArgumentMatcher

Users can now use ArgumentMatcher as a Cats typeclass, gaining access to ContravariantMonoidal and MonoidK operations. This allows combining matchers using standard Cats abstractions, such as combining multiple matchers with \combineK\ (AllOf) or transforming them with \contramap\.

cats/src/main/scala/org/mockito/cats/instances · high confidence

Add Scalaz integration for mocking effect types

This release adds a new \scalaz\ module to Mockito, enabling users to mock methods that return Scalaz effect types (such as \Task\, \IO\, or \Validation\). The integration provides idiomatic stubbing methods like \whenF\, \doReturnF\, \doFailWith\, and \doAnswerF\ (along with their \FG\ variants for nested effects), allowing developers to configure mock behavior for asynchronous or error-handling code using Scalaz's \Applicative\ and \MonadError\ type classes. It also includes an implicit conversion from Scalaz's \Equal\ to Scalactic's \Equality\ to support argument matching on effect types.

scalaz/src/main · high confidence

Add specs2 integration module

A new specs2 module has been added, providing integration between Mockito and the specs2 testing framework. This includes the \Mockito\ trait and supporting classes that enable specs2-style verification syntax (such as \there.was\ and \inOrder\), argument matchers compatible with specs2 matchers, and partial function call matching, allowing users to write Mockito tests using specs2 conventions.

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 macros (such as \was\, \were\, and \got\) and match result combinators, ensuring that existing specs2-based tests continue to function correctly when upgraded to Scala 3.

specs2/src/main/scala-3 · high confidence

Idiomatic Cats syntax for mocking effect types

The Cats integration now provides idiomatic syntax for mocking methods that return effect types (e.g., \F\[T\]\ or \F\[G\[T\]\]\). Users can use \whenF\ and \whenFG\ to stub effect-returning methods, and \doReturnF\, \doFailWithF\, \doAnswerF\ (along with their \G\ variants) to define stubbing behaviors that automatically lift values into the effect context using Cats \Applicative\ and \ApplicativeError\ instances. Additionally, the integration now prioritizes Cats \Eq\ for argument matching over Scalactic \Equality\, ensuring consistent behavior for types with Cats equality instances.

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 (target/, build/, .bsp/), SBT memory settings in \.sbtopts\, and a \scalafmt.conf\ enforcing Scala 2.13/3 formatting with a 180-column limit. A \LICENSE\ file (MIT) is added, and the \README.md\ is populated with comprehensive documentation covering dependency setup, migration notes for versions 1.0.0 through 2.1.0, and usage examples for the idiomatic API, MockitoSugar, and ArgumentMatchersSugar. Additionally, a \.scala-steward.conf\ is introduced to automate dependency updates on a weekly basis.

(repo-wide) · high confidence

Introduces Scala-native stubbing abstractions and value class support

This change introduces new Scala-specific stubbing components in the \org.mockito.stubbing\ package, including \DefaultAnswer\, \ScalaAnswer\, and \ScalaBaseStubbing\. These additions provide idiomatic ways to define mock behaviors using Scala functions and support Scala value classes, allowing users to stub methods with value class parameters and return types more naturally than with the standard Java Mockito API.

common/src/main/scala/org/mockito/stubbing · high confidence

Introduces ScalaInvocation for Scala-specific mock handling

Adds a new ScalaInvocation class that implements the Invocation interface to handle Scala-specific invocation details, including support for Scala's Prettifier for argument formatting and EqTo matchers for argument equality checks.

common/src/main/scala/org/mockito/internal/invocation · high confidence

New Scala-specific argument matchers and collection matchers

The library now provides a comprehensive set of Scala-native argument matchers in the \org.mockito.matchers\ package. Users can now use idiomatic Scala collection matchers (\anyList\, \anySeq\, \anyIterable\, \anySet\, \anyMap\) that correctly handle Scala's immutable collections, avoiding type mismatches with Java's \java.util\ variants. New numeric comparison matchers (\n \>\, \n \>=\, \n \<\, \n \<=\, and \=\~\ for floating-point tolerance) allow for expressive verification of numeric arguments. String matching capabilities have been expanded with \matches\, \startsWith\, \contains\, and \endsWith\. The \eqTo\ matcher now leverages Scalactic's \Equality\ for customizable value comparison and supports value classes. Additionally, \argMatching\ now supports partial functions for pattern-matching style verifications, and primitive-specific matchers (\byteThat\, \intThat\, etc.) are available to avoid unnecessary implicit conversions.

common/src/main/scala/org/mockito/matchers · high confidence

New Scalatest integration traits for session management and automatic mock reset

The scalatest module now provides dedicated integration traits that improve test reliability and lifecycle management. Users can mix in \IdiomaticMockito\ or \AsyncIdiomaticMockito\ to use idiomatic verification syntax with proper Scalatest assertion types. A new \MockitoSessionFixture\ ensures that the Mockito session is properly closed after every test, even if the test fails or throws an exception, preventing resource leaks. Additionally, \ResetMocksAfterEachTest\ and \ResetMocksAfterEachAsyncTest\ traits are introduced to automatically reset all mocks after each test execution, simplifying test isolation for suites that share mock instances.

scalatest/src/main · high confidence

New idiomatic Scala DSL for stubbing and verification

The core module now provides a new idiomatic API for mocking, allowing users to write stubs and verifications using natural Scala syntax. Stubbing is supported via postfix methods like \returns\, \shouldReturn\, \throws\, and \answers\, as well as a prefix-style \willBe\ syntax (e.g., \value willBe returned by mock\). Verification is available through postfix operators such as \was called\, \wasNever\, and \wasCalled once\, alongside a new prefix \expect\ DSL (e.g., \expect.one(mock).to(call)\) for safer prefixed verifications. This DSL is implemented using macros for both Scala 2 and Scala 3, with version-specific files in \scala-2\ and \scala-3\ directories, and includes support for partial functions and lenient stubbing.

core · high confidence

New idiomatic stubbing and matcher APIs for Scala

This release introduces a new idiomatic API for stubbing and verification, providing macro-based DSLs like \when(mock.method).shouldReturn(value)\ and \mock.method.willBe(ReturnedBy(value).by(stubbing))\ that replace the traditional \when/thenReturn\ pattern. It also adds a new \common\ module containing Scala-native argument matchers (\AllOf\, \EqTo\, \ProductOf\, \Transformed\) and a \ReturnsSmartNulls\ default answer. The idiomatic API is available for both Scala 2 and Scala 3, with Scala 3 utilizing inline macros for better type safety and error messages.

repository · high confidence

Scala 3 macro implementations for idiomatic stubbing and verification DSLs

The macro module now includes native Scala 3 implementations for the idiomatic stubbing and verification DSLs, running alongside the existing Scala 2 macros. This adds Scala 3 support for the 'do something by' stubbing syntax (e.g., \doesNothing\, \returnedBy\, \answeredBy\, \thrownBy\, \calledBy\), the prefix expectation syntax (\expect calls to\, \expect calls on\), and the verification syntax (\was\, \wasNever\). The Scala 3 macros utilize the \scala.quoted\ API to transform user DSL expressions into standard Mockito runtime calls, handling argument transformation, matcher detection, and value-class support specific to Scala 3's type system.

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

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 and dependencies via new files in the \project/\ directory. The build tool is set to sbt version 1.13.0, with the sbt-scalafmt 2.6.2 plugin added for code formatting. Dependencies are centralized in \Dependencies.scala\, specifying mockito-core 5.23.0, ScalaTest 3.2.20, Specs2 4.23.0, Cats 2.13.0, and Scalaz 7.3.9, among others, establishing the baseline library versions for the project.

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, providing access to the latest features, performance improvements, and bug fixes available in this release.

gradle · high confidence

Written by watchdog.canine.dev from the codebase's own history, inside the signed delivery this page is composed from.

How this codebase got here

Baseline

  • First survey — no prior run to compare against. CAI 63.

Lenses

  • Code Health 91
  • Architecture 100
  • Maturity 57
  • Readiness 58
  • Security 67

Changes since last survey

  • 300 commits — 280 feature/other, 20 fixes

By area

  • (root) — 94 commits
  • project/Dependencies.scala — 44 commits
  • project/build.properties — 39 commits
  • (repo) — 26 commits
  • common/src — 22 commits
  • scalatest/src — 14 commits
  • macro/src — 13 commits
  • .github/workflows — 11 commits
  • project/plugins.sbt — 10 commits
  • gradle/shipkit.gradle — 8 commits
  • core/src — 7 commits
  • cats/src — 4 commits
  • macro-common/src — 3 commits
  • scalaz/src — 2 commits
  • specs2/src — 2 commits
  • .bsp/sbt.json — 1 commit

Notable commits

  • fix: #350 Fix Refelction utils for java 13+ (#356)
  • fix: Add regression tests for scalatest module (#647)
  • fix: Fix Scala 3 shouldReturn/mustReturn inference for polymorphic methods (#652)
  • fix: Fix StackOverflow on generics resolution (#237)
  • fix: Fix ci.yml Remove build status from README.md
  • fix: Fix issue with scalatest inheritance
  • fix: Fix link to tests (#249) [ci skip]
  • fix: Fix task name in release job (#567)
  • fix: Fixed CI releases
  • fix: Fixed bug in CI
  • fix: Fixed the CI releases
  • fix: Fixed the build
  • fix: Fixed the release build
  • fix: Fixes Issue #251 (#284) [ci skip-release]
  • fix: Fixes Issue #254 (#283) [ci skip-release]
  • fix: Fixes Issue #256 (#282) [ci skip-release]
  • fix: Fixes Issue #303 (#308)
  • fix: Merge pull request #337 from mockito/fix-build
  • fix: Some fixes for Scala 3 mock-method metadata (#641)
  • fix: Upgrade Scala 3 LTS to 3.3.8 and fix ambiguous shouldReturn/mustReturn overloads
  • …and 280 more

Architecture

  • 0 containers · 1 bounded contexts · 0 dependency edges (baseline)

Written by watchdog.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 20 September 2026 at a pinned commit. It is not a live figure and does not change until the project is measured again.
  • Measured at commit 6c0a51a41cf2241ce3dccbba87ef9eb4230587d0 — the exact code this score is about.
  • Scored under rubric-2026.09.15 — the same rubric and the same method as every other entry in this index.
  • Measured by watchdog.canine.dev using codehealth-analyzer preprod-b51f968c9b10.