# Mockito

Published articles for Mockito.

This is one page of public article previews, not the complete archive. Follow Next page to continue. Summaries are not the original full articles.

## Kotlin and Java interoperability: Traps and gotchas

DevFeed: [Kotlin and Java interoperability: Traps and gotchas](<https://devfeed.tech/articles/kotlin-and-java-interoperability-traps-and-gotchas-39204.md>)

Original publisher: [Read original article](<https://kt.academy/article/ak-java-interop-4>)

Published: 2023-08-21T00:15:00Z

Content type: tutorial

Language: en

Sources: [Kt. Academy](<https://devfeed.tech/sources/kt-academy.md>)

Topics: [interoperability](<https://devfeed.tech/topics/interoperability.md>), [Java](<https://devfeed.tech/topics/java.md>), [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [gotchas](<https://devfeed.tech/topics/gotchas.md>), [exceptions](<https://devfeed.tech/topics/exceptions.md>)

Tags: [gotchas](<https://devfeed.tech/tags/gotchas.md>), [interoperability](<https://devfeed.tech/tags/interoperability.md>), [java](<https://devfeed.tech/tags/java.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [mockito](<https://devfeed.tech/tags/mockito.md>), [unit-test](<https://devfeed.tech/tags/unit-test.md>), [workshop-learning-programming](<https://devfeed.tech/tags/workshop-learning-programming.md>)

### AI overview

This tutorial explains surprising aspects of Kotlin and Java interoperability, including return types, function types and functional interfaces, Java keywords used in Kotlin names, Mockito's `when` function, Kotlin/JVM naming constraints, and Java checked exceptions.

### Source excerpt

The parts of Kotlin and Java interoperability that might be surprising or counterintuitive.

## Answers in mockito

DevFeed: [Answers in mockito](<https://devfeed.tech/articles/answers-in-mockito-27313.md>)

Original publisher: [Read original article](<https://blog.pchudzik.com/201909/mockito-answers/>)

Published: 2019-09-22T00:00:00Z

Content type: tutorial

Language: en

Sources: [Paweł Chudzik](<https://devfeed.tech/sources/pawe-chudzik.md>)

Topics: [Mocking](<https://devfeed.tech/topics/mocking.md>), [Library](<https://devfeed.tech/topics/library.md>), [test](<https://devfeed.tech/topics/test.md>), [legacy](<https://devfeed.tech/topics/legacy.md>), [Refactoring](<https://devfeed.tech/topics/refactoring.md>), [Exception](<https://devfeed.tech/topics/exception.md>)

Tags: [developer](<https://devfeed.tech/tags/developer.md>), [exception](<https://devfeed.tech/tags/exception.md>), [legacy](<https://devfeed.tech/tags/legacy.md>), [mocking](<https://devfeed.tech/tags/mocking.md>), [mockito](<https://devfeed.tech/tags/mockito.md>), [refactoring](<https://devfeed.tech/tags/refactoring.md>), [techniques](<https://devfeed.tech/tags/techniques.md>), [test](<https://devfeed.tech/tags/test.md>)

### AI overview

This tutorial explains Mockito stubbing strategies and answers, including default returns, real method calls, null handling, self-returning builders, generated mocks, and deep stubs. It also discusses when these techniques may indicate legacy code or problematic design.

### Source excerpt

Mocking library is an important tool in every developer toolbox. Sometimes you want to do things that at first glance look a bit more complex than returning number 42 from some method. Let's see what stubbing techniques are available in Mockito out of the box and what they offer. Read more

## Cleaning Up Test Files and Resources

DevFeed: [Cleaning Up Test Files and Resources](<https://devfeed.tech/articles/superior-testing-cleaning-up-29376.md>)

Original publisher: [Read original article](<https://arturdryomov.dev/posts/superior-testing-cleaning-up/>)

Author: Artur Dryomov

Published: 2019-06-06T00:00:00Z

Content type: tutorial

Language: en

Sources: [Artur Dryomov](<https://devfeed.tech/sources/artur-dryomov.md>)

Topics: [Testing](<https://devfeed.tech/topics/testing.md>), [Memory Leaks](<https://devfeed.tech/topics/memory-leaks.md>), [Mocking](<https://devfeed.tech/topics/mocking.md>), [Filesystems](<https://devfeed.tech/topics/filesystems.md>), [Java](<https://devfeed.tech/topics/java.md>), [Kotlin](<https://devfeed.tech/topics/kotlin.md>)

Tags: [files](<https://devfeed.tech/tags/files.md>), [junit](<https://devfeed.tech/tags/junit.md>), [memory-leaks](<https://devfeed.tech/tags/memory-leaks.md>), [mocking](<https://devfeed.tech/tags/mocking.md>), [mockito](<https://devfeed.tech/tags/mockito.md>), [testing](<https://devfeed.tech/tags/testing.md>)

### AI overview

This tutorial explains how cleanup practices can improve tests. It discusses memory leaks and Mockito inline mocking, suggests using stubs that do not track invocations when verification is unnecessary, and recommends creating test files only in temporary directories and deleting them after each run.

### Source excerpt

There is a game called Viscera Cleanup Detail. The task in this game is to... clean things up. Well, it is a bit more exciting since it involves alien invasions, but at the end of the day players become space janitors. It is surprisingly addictive. Cleaning things is useful and helpful in a lot of ways. Developers understand that, but usually there is an additional motivation to keep things in order -- users. Nobody wants a product that breaks because there is not enough memory or wrecks havoc across the file system. The picture is very different with tests -- often they become a second class citizen. It shouldn't be this way.

## Superior Testing: Check Your Checks

DevFeed: [Superior Testing: Check Your Checks](<https://devfeed.tech/articles/superior-testing-check-your-checks-29375.md>)

Original publisher: [Read original article](<https://arturdryomov.dev/posts/superior-testing-check-checks/>)

Author: Artur Dryomov

Published: 2019-03-27T00:00:00Z

Content type: opinion

Language: en

Sources: [Artur Dryomov](<https://devfeed.tech/sources/artur-dryomov.md>)

Topics: [Testing](<https://devfeed.tech/topics/testing.md>), [Programming](<https://devfeed.tech/topics/programming.md>), [async](<https://devfeed.tech/topics/async.md>), [test](<https://devfeed.tech/topics/test.md>), [SDK](<https://devfeed.tech/topics/sdk.md>)

Tags: [async](<https://devfeed.tech/tags/async.md>), [code](<https://devfeed.tech/tags/code.md>), [errors](<https://devfeed.tech/tags/errors.md>), [false-positives](<https://devfeed.tech/tags/false-positives.md>), [mockito](<https://devfeed.tech/tags/mockito.md>), [testing](<https://devfeed.tech/tags/testing.md>), [ui](<https://devfeed.tech/tags/ui.md>)

### AI overview

The article discusses false positives in software tests, focusing on assertions and Mockito verifications. It explains that checking only a result or an invocation can miss side effects, especially in asynchronous code and UI behavior.

### Source excerpt

False positives. Such an interesting combination of words, isn't it? The nature of false positives is mostly human. We misinterpret conditions, define them wrong, forget about effects -- but the machine obeys. We get what we want but not what we need. This is dangerous. The civilization downfall in various science fiction books is a false positive result. The AI gets instructions to eliminate all threats, humanity becomes the threat, roll the action scene. This is so not new that we got used to it.

## Introducing springmock

DevFeed: [Introducing springmock](<https://devfeed.tech/articles/introducing-springmock-27275.md>)

Original publisher: [Read original article](<https://blog.pchudzik.com/201707/springmock-v1/>)

Published: 2017-07-25T00:00:00Z

Content type: article

Language: en

Sources: [Paweł Chudzik](<https://devfeed.tech/sources/pawe-chudzik.md>)

Topics: [Library](<https://devfeed.tech/topics/library.md>), [Mocking](<https://devfeed.tech/topics/mocking.md>)

Tags: [library](<https://devfeed.tech/tags/library.md>), [mocking](<https://devfeed.tech/tags/mocking.md>), [mockito](<https://devfeed.tech/tags/mockito.md>), [spring](<https://devfeed.tech/tags/spring.md>), [springboot](<https://devfeed.tech/tags/springboot.md>), [tests](<https://devfeed.tech/tags/tests.md>)

### AI overview

The author introduces springmock, a library that injects Spock mocks into Spock Specification classes in Spring integration tests. It supports Spock and Mockito as mock and spy providers and reduces the boilerplate needed for mock injection.

### Source excerpt

I've been using springboot for some time now, but there was that one thing that bugged me a lot. While writing integration tests with mocks you are forced to use mockito as the mocking library. That's great and easy to understand if you are not using spock. The problem is that in spock there are better ways to mock stuff... Read more

## How to mock final classes on Kotlin using Mockito 2 (KAD 23)

DevFeed: [How to mock final classes on Kotlin using Mockito 2 (KAD 23)](<https://devfeed.tech/articles/how-to-mock-final-classes-on-kotlin-using-mockito-2-kad-23-27203.md>)

Original publisher: [Read original article](<https://antonioleiva.com/mockito-2-kotlin>)

Published: 2017-05-02T00:00:00Z

Content type: tutorial

Language: en

Sources: [Antonio Leiva](<https://devfeed.tech/sources/antonio-leiva.md>)

Topics: [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [Mocking](<https://devfeed.tech/topics/mocking.md>), [Testing](<https://devfeed.tech/topics/testing.md>)

Tags: [2](<https://devfeed.tech/tags/2.md>), [classes](<https://devfeed.tech/tags/classes.md>), [how-to](<https://devfeed.tech/tags/how-to.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [mocking](<https://devfeed.tech/tags/mocking.md>), [mockito](<https://devfeed.tech/tags/mockito.md>), [testing](<https://devfeed.tech/tags/testing.md>)

### AI overview

This tutorial explains how to mock final Kotlin classes with Mockito 2. It covers updating the Mockito dependency, enabling experimental support for final-class mocking through a configuration file, and mocking Kotlin properties.

### Source excerpt

Everything Android, Kotlin and other random topics

## Using Mockito 2.x on Android

DevFeed: [Using Mockito 2.x on Android](<https://devfeed.tech/articles/using-mockito-2-x-on-android-28653.md>)

Original publisher: [Read original article](<https://jeroenmols.com/blog/2017/01/17/mockitoandroid/>)

Author: info@jeroenmols.com (Jeroen Mols)

Published: 2017-01-17T00:00:00Z

Content type: tutorial

Language: en

Sources: [Jeroen Mols](<https://devfeed.tech/sources/jeroen-mols.md>)

Topics: [Android](<https://devfeed.tech/topics/android.md>), [Code](<https://devfeed.tech/topics/code.md>)

Tags: [2](<https://devfeed.tech/tags/2.md>), [android](<https://devfeed.tech/tags/android.md>), [blogs](<https://devfeed.tech/tags/blogs.md>), [dependencies](<https://devfeed.tech/tags/dependencies.md>), [instrumentation](<https://devfeed.tech/tags/instrumentation.md>), [mockito](<https://devfeed.tech/tags/mockito.md>), [testing](<https://devfeed.tech/tags/testing.md>), [unit-tests](<https://devfeed.tech/tags/unit-tests.md>)

### AI overview

This tutorial explains how Mockito 2.x added native support for Android instrumentation tests. It describes replacing the earlier dependency-based approach with the mockito-android artifact and notes behavior changes involving null values and matchers.

### Source excerpt

The Mockito team is on fire lately! Not only did they add support to mock final classes and methods, but now they allow running Mockito directly onto an actual Android device.

## Extending Mockito

DevFeed: [Extending Mockito](<https://devfeed.tech/articles/extending-mockito-28651.md>)

Original publisher: [Read original article](<https://jeroenmols.com/blog/2016/10/31/mockitomatchers/>)

Author: info@jeroenmols.com (Jeroen Mols)

Published: 2016-10-31T00:00:00Z

Content type: tutorial

Language: en

Sources: [Jeroen Mols](<https://devfeed.tech/sources/jeroen-mols.md>)

Topics: [Mocking](<https://devfeed.tech/topics/mocking.md>), [Java](<https://devfeed.tech/topics/java.md>), [unit tests](<https://devfeed.tech/topics/unit-tests.md>), [Framework](<https://devfeed.tech/topics/framework.md>)

Tags: [android](<https://devfeed.tech/tags/android.md>), [blogs](<https://devfeed.tech/tags/blogs.md>), [examples](<https://devfeed.tech/tags/examples.md>), [framework](<https://devfeed.tech/tags/framework.md>), [github](<https://devfeed.tech/tags/github.md>), [how-to](<https://devfeed.tech/tags/how-to.md>), [java](<https://devfeed.tech/tags/java.md>), [library](<https://devfeed.tech/tags/library.md>), [mastodon](<https://devfeed.tech/tags/mastodon.md>), [mocking](<https://devfeed.tech/tags/mocking.md>), [mockito](<https://devfeed.tech/tags/mockito.md>), [testing](<https://devfeed.tech/tags/testing.md>), [tests](<https://devfeed.tech/tags/tests.md>), [unit-tests](<https://devfeed.tech/tags/unit-tests.md>)

### AI overview

A tutorial on extending Mockito with custom argument matchers. It explains how custom matchers can simplify verification of collection contents in unit tests and mentions a GitHub library of collection matchers.

### Source excerpt

Due to its clean simple api, Mockito has become world's most popular Java mocking framework. After having covered all of its basics, it's time to spice things up and start extending Mockito.

## Android Testing with Mockito

DevFeed: [Android Testing with Mockito](<https://devfeed.tech/articles/testing-made-sweet-with-a-mockito-28647.md>)

Original publisher: [Read original article](<https://jeroenmols.com/blog/2016/06/24/droidcondetalk/>)

Author: info@jeroenmols.com (Jeroen Mols)

Published: 2016-06-24T00:00:00Z

Content type: article

Language: en

Sources: [Jeroen Mols](<https://devfeed.tech/sources/jeroen-mols.md>)

Topics: [Testing](<https://devfeed.tech/topics/testing.md>), [Android](<https://devfeed.tech/topics/android.md>), [unit tests](<https://devfeed.tech/topics/unit-tests.md>), [Framework](<https://devfeed.tech/topics/framework.md>), [Test-driven development](<https://devfeed.tech/topics/tdd.md>)

Tags: [android](<https://devfeed.tech/tags/android.md>), [android-testing](<https://devfeed.tech/tags/android-testing.md>), [blogs](<https://devfeed.tech/tags/blogs.md>), [code-coverage](<https://devfeed.tech/tags/code-coverage.md>), [droidcon](<https://devfeed.tech/tags/droidcon.md>), [mockito](<https://devfeed.tech/tags/mockito.md>), [sdk](<https://devfeed.tech/tags/sdk.md>), [tdd](<https://devfeed.tech/tags/tdd.md>), [testing](<https://devfeed.tech/tags/testing.md>), [unit-tests](<https://devfeed.tech/tags/unit-tests.md>)

### AI overview

This article recaps a Droidcon Berlin 2016 talk about Android testing with Mockito. It explains mocks, stubs, testing Android code and final methods, and using relevant test data, with sample code available on GitHub.

### Source excerpt

At Droidcon Berlin 2016 I had a great time talking about testing using the Mockito framework. While the talk wasn't recorded unfortunately, the great folks at Voice Republic recorded an audio version which you can listen to as a podcast or together with the slides.

## Using Mockito's InjectMocks

DevFeed: [Using Mockito's InjectMocks](<https://devfeed.tech/articles/using-mockito-s-injectmocks-37781.md>)

Original publisher: [Read original article](<https://carlosbecker.com/posts/injectmocks/>)

Author: Carlos Alexandro Becker

Published: 2015-03-05T00:00:00Z

Content type: tutorial

Language: en

Sources: [Carlos Becker](<https://devfeed.tech/sources/carlos-becker.md>)

Topics: [Testing](<https://devfeed.tech/topics/testing.md>), [Java](<https://devfeed.tech/topics/java.md>)

Tags: [java](<https://devfeed.tech/tags/java.md>), [mock](<https://devfeed.tech/tags/mock.md>), [mockito](<https://devfeed.tech/tags/mockito.md>), [test](<https://devfeed.tech/tags/test.md>), [testing](<https://devfeed.tech/tags/testing.md>), [using](<https://devfeed.tech/tags/using.md>)

### AI overview

A quick Java testing tip that demonstrates how Mockito's @InjectMocks can inject mocked dependencies into a class under test, avoiding manual constructor calls. The article notes that the annotation has limitations but works for most cases.

### Source excerpt

FYI: Like the previous post, this is a really quick tip.

## Using JUnit Rules to simplify your tests

DevFeed: [Using JUnit Rules to simplify your tests](<https://devfeed.tech/articles/using-junit-rules-to-simplify-your-tests-37795.md>)

Original publisher: [Read original article](<https://carlosbecker.com/posts/junit-rules/>)

Author: Carlos Alexandro Becker

Published: 2014-11-18T00:00:00Z

Content type: tutorial

Language: en

Sources: [Carlos Becker](<https://devfeed.tech/sources/carlos-becker.md>)

Topics: [test](<https://devfeed.tech/topics/test.md>), [Code](<https://devfeed.tech/topics/code.md>), [exceptions](<https://devfeed.tech/topics/exceptions.md>), [interface](<https://devfeed.tech/topics/interface.md>)

Tags: [code](<https://devfeed.tech/tags/code.md>), [exceptions](<https://devfeed.tech/tags/exceptions.md>), [interface](<https://devfeed.tech/tags/interface.md>), [junit](<https://devfeed.tech/tags/junit.md>), [mockito](<https://devfeed.tech/tags/mockito.md>), [simplify](<https://devfeed.tech/tags/simplify.md>), [tests](<https://devfeed.tech/tags/tests.md>)

### AI overview

This tutorial explains how to use JUnit Rules to reduce repeated setup and teardown code in tests. It covers timeouts, temporary folders, expected exceptions, custom rules, Mockito initialization, external resources, and integration-test server lifecycle management.

### Source excerpt

Have you ever written JUnit tests extending a class that does some before and after work, so you didn't have to repeat that code in various test classes?