mockito-kotlin
mockk
Our great sponsors
mockito-kotlin | mockk | |
---|---|---|
6 | 17 | |
3,071 | 5,280 | |
0.0% | 0.6% | |
6.1 | 8.6 | |
18 days ago | 17 days ago | |
Kotlin | Kotlin | |
MIT License | Apache License 2.0 |
Stars - the number of stars that a project has on GitHub. Growth - month over month growth in stars.
Activity is a relative number indicating how actively a project is being developed. Recent commits have higher weight than older ones.
For example, an activity of 9.0 indicates that a project is amongst the top 10% of the most actively developed projects that we are tracking.
mockito-kotlin
-
Best practices for Unit Testing Android Apps with Mockk, Kotest and others
As you can see, I create mockUsersRepository object using mock( function. Then, in setup() method, I set up this repository in such a way so that it would return a list of hardcoded values. After this, on top of everything else, I check if, for mockUsersRepository object, getUsers method was called with verify function, in the test method. It’s important to note that Mockito is a very old framework and was originally written for Java. When Kotlin appeared, it turned out that out of the box this framework can work with some limitations, which is why an extension, mockito-kotlin, was released. The example above was written with it. Another Mockito’s limitation was that it was impossible to mock final classes and static methods, and all classes are final by default in Kotlin. Currently, this is solved through mockito-inline but, before, it was a serious limitation. In respect to Java development, there was and is an alternative for Android developers, PowerMock.
-
Why don't you write unit tests and integration tests to ksp project
In the demo project, I used junit and mockito. One thing we need to pre-learn do the unit test, that is ksp class diagram.
-
Spring with java vs Spring with kotlin
What's wrong with Mockito for Kotlin?
-
From Java to Kotlin. There and back again
Mockito does not work correctly with Kotlin types out of the box. Spring recommends using Mockk. There is also a special module for Mockito, which adds support for Kotlin - Mockito-Kotlin.
- Avoiding Stringly-typed in Kotlin
- Argument(s) are different! Wanted: Unit test
mockk
-
For those DAO, Services, how about using static objects with mockk for test
The official suggests using dagger/hilt to inject them. However, they could be static based on the static ApplicationContext. Although Dagger/hilt aids in unit testing, mockk can accomplish this easily as well by modifying bytecode during run time. As for the stability, `mockk` has 5000+ stars on GitHub and keeps renewing.
-
Tests Everywhere - Kotlin
We can create it as a class as MockK is able to mock final classes.
-
🧪 **Demystifying Kotlin Unit Testing**: Your Odyssey to Code Confidence! 🚀
Mockk Documentation
-
Best practices for Unit Testing Android Apps with Mockk, Kotest and others
Mockk is a rather new framework; it was originally designed for Kotlin, although it supports Java as well. Before mockito-kotlin was released, using Mockk was much easier and beneficial for Kotlin developers, but right now both these frameworks have nearly the same set of features and similar syntax. For example, assume that our function loadUsers is no longer synchronous, but rather suspended:
-
LocalDateTime.now() mockk
You can use mockkStatic for that, see docs. Also don't forget to unmockkStatic afterwards.
-
reflective-mockk: Stub methods programmatically using kotlin-reflect
WARNING: reflective-mockk is currently powered by a reflective “hack” on mockK, and is thereby subject to removal/breakage by the mockK team at any time. If you enjoy this library & want it to be officially supported, post a comment saying so on this PR: https://github.com/mockk/mockk/pull/1005.
-
mockk VS mockative - a user suggested alternative
2 projects | 9 Nov 2022
- Are there any plans to make a better build system for Kotlin than Gradle?
-
Spring with java vs Spring with kotlin
https://mockk.io/ is great, too.
-
From Java to Kotlin. There and back again
Mockito does not work correctly with Kotlin types out of the box. Spring recommends using Mockk. There is also a special module for Mockito, which adds support for Kotlin - Mockito-Kotlin.
What are some alternatives?
Kotest - Powerful, elegant and flexible test framework for Kotlin with additional assertions, property testing and data driven testing
kotlin-faker - Port of a popular ruby faker gem written in kotlin. Generate realistically looking fake data such as names, addresses, banking details, and many more, that can be used for testing and data anonymization purposes.
spek - A specification framework for Kotlin
balin - Balin is an automation library for Kotlin. It's basically a Selenium-WebDriver wrapper inspired by Geb.
mock-fuel - JUnit 5 extension to easily test with the http client Fuel for Kotlin
Kluent - Fluent Assertion-Library for Kotlin
kotlin-logging - Lightweight Multiplatform logging framework for Kotlin. A convenient and performant logging facade.
strikt - An assertion library for Kotlin
kotlinfixture - Fixtures for Kotlin providing generated values for unit testing