Testing Kotlin Flows in Android using Turbine
Kotlin Testing
by Daniel Atitienei
10M ago
In this article, we will explore some tips and techniques for testing Kotlin Flows in Android apps, helping you write more reliable and robust code. Why is this important? Testing is an essential part of software development, and it becomes even more critical when working with asynchronous code like Flows. Setup Go ahead to :app/build.gradle and add Turbine. dependencies {    // You can also use JUnit instead of kotlin-test    testImplementation("org.jetbrains.kotlin:kotlin-test")    testImplementation("app.cash.turbine:turbine:0.12.1") } What is Turbine and how ..read more
Visit website
4 Ways to Leverage Kotest Specs for More Robust Testing
Kotlin Testing
by Jarosław Michalik
11M ago
When it comes to testing in Kotlin, we often default to jUnit as the go-to framework. However, there's an alternative that offers a variety of powerful features – Kotest. Kotest provides a variety of spec styles, each with its unique capabilities, that make writing tests a breeze. Whether you're looking for a straightforward, linear approach or a more complex, hierarchical structure, there's a Kotest spec that fits the bill. This article will walk you through four of these spec styles: StringSpec, FunSpec, FreeSpec, and BehaviorSpec. By the end, you should have a good understanding of each st ..read more
Visit website
How to mock data class?
Kotlin Testing
by Jarosław Michalik
1y ago
Short answer: you don't. Instead: create additional function. Let's suppose, you have User data class. data class User(val id: Int, val name: String, val email: String) The easiest way to "mock" it would be to use default values. But does default values always makes sense? If it's json model, it may not be the best solution. Create additional function createUser that will accept the same values as your data class. Now you can use "defaults" by calling that function. fun createUser( id: Int = 1, name: String = "", email: String = "" ): User { return User(id, name, email ..read more
Visit website
Breaking the Loop: A 5-Step Process to Refactor Your Old, Untestable Codebase and Improve Its Quality"
Kotlin Testing
by Jarosław Michalik
1y ago
Are you stuck in a loop of having an old codebase that's not testable, but not being able to refactor it because there's no test coverage? This is a common challenge that many software development teams face, but there's a way out. In this article, we'll explore a 5-step process to break the cycle and improve the quality of your codebase. Since I'm discussing a process to improve code quality and testability, I intentionally did not include actual code examples. My focus is on the process and methodology rather than specific programming languages or technologies. Step 1: Identify the most cri ..read more
Visit website
Idiomatic Kotlin in tests: idiomatic stubbings
Kotlin Testing
by Jarosław Michalik
1y ago
Stub is a type of test double, which is a generic term for objects that stand in the place of other objects in a test scenario. ? We use stubs for returning predefined values Such objects are used to help with testing and provide a guarantee that the code being tested will behave in a certain way. The most common types of test doubles are mocks fakes stubs spies ? Very often we refer to all test doubles as "mocks" In this article you will learn several ways of creating stubs… using Kotlin idioms. A stub is a test double that returns predetermined values instead of invoking real methods ..read more
Visit website
Open Android Unit Testing Workshops – 17.02.2023
Kotlin Testing
by Jarosław Michalik
1y ago
We are starting in... What will you get out of this workshop? You will get a deep understanding of test concepts You will learn to write clean and predictable tests on Android with MVVM, Kotlin Flow You will learn the most common mistakes in testing and how to deal with them Throughout the workshop you will have access to a mentor, so any issues will be addressed on the spot. Agenda Bulletproof unit testing configuration Understand testing concepts Master test doubles Testing patterns: unit testing use cases with suspend functions Testing patterns: unit testing MVVM’s ViewModel Testing Kot ..read more
Visit website
Unit testing on Android – test pyramide
Kotlin Testing
by Jarosław Michalik
1y ago
Let's start not from programming, but from the home construction industry. We will deal with windows in houses or apartments. In such windows we usually find handles – the handle should open the window. The window system with the handle can be checked in several ways, including: Does the handle fit the given window doors? Does the handle, when turned, move the elements of the lock? Does the handle, when turned, unlock the window? The analogy is justified only by a popular gif. Let's now translate these requirements into programming world. Let the window system be our app. Does the handle ..read more
Visit website
Startuje III edycja kursu Android Unit Testy!
Kotlin Testing
by Jarosław Michalik
1y ago
Kurs Android ❤️ Unit Testy 15 modułów- kompletny program nauki unit testów na Androidzie dożywotni dostęp do materiałów (to uniwersalna wiedza, będziesz do niej sięgać za rok, czy pięć lat) aktualizacje kursu we wszystkich przyszłych edycjach wjazd na nasz prywatny mastermind na Slacku nagrania spotkań LIVE spotkania na żywo podczas których rozkminiamy ciekawe przypadki nowość w trzeciej edycji – cały moduł poświęcony strategii testowania GraphQL Kompletny kurs unit testów dla programistów Androida Dołącz teraz ..read more
Visit website
Intro to jUnit5 for Android Developers (free course)
Kotlin Testing
by Jarosław Michalik
1y ago
Do you know that Android Studio generates sample tests with an archaic framework? A sample test in a new project - ExampleUnitTest.kt - uses the import annotation of the test method from jUnit4. The problem is that jUnit in version 4.x is no longer actively developed. It only gets the necessary security fixes. For comparison - the new version of the same framework, that is, jUnit5 has been with us since 2017. 5 years in software dev is an astronomical amount of time. You can still find entries on the internet exclusively for the archaic version. It's time to put an end to it! Here is a... min ..read more
Visit website
De-mock your tests
Kotlin Testing
by Jarosław Michalik
1y ago
Examples of de-mocking test code as presented on Droidcon Berlin 2022. Subscribe for KotlinTesting updates Subscribe Loading... Subscribe Loading... Thank you! You have successfully joined our subscriber list. De-Mocking CRUD Service Let's consider a local database described by an interface: interface LocalDatabase { fun save(list: List<ProductEntity>) fun getAll(): List<ProductEntity> } It can be implemented with SQL by Room, or with other database of your choice. To be honest, it could be even backend code with Postgres or Mongo. Doesn't matter – we want to use some ..read more
Visit website

Follow Kotlin Testing on FeedSpot

Continue with Google
Continue with Apple
OR