Testing

An attempt to unit test generated DataBinding code

But why? I use databinding a lot in my Android projects. It fits nicely with ViewModel and general MVVM approach. I also make use of databinding in small layouts – such as RecyclerView row or reusable <include> layouts. How does databinding works in general? You enable special build feature in build.gradle: android { (…) buildFeatures …

An attempt to unit test generated DataBinding code Read More »

Parameterized tests with Kotest

We make use of parameterized test when we want to check system under test against various inputs while using same or similar test logic. Real life example for parameterized test may be unit conversion – meters to kilometers converter for the sake of UI display. In some place in an application (either web or mobile) …

Parameterized tests with Kotest Read More »

Handling exceptions in tests: Junit & Kotest

Exceptions and throwables are essential part of many Java APIs. They are useful for modeling application domain layer and controlling program execution flow. We’ll be working on following piece of code: class CustomException : Exception()class SystemUnderTest { fun doStuff() { throw CustomException() }} Annotated Junit4 method class AssertionsOnExceptionsTest { @Test(expected = CustomException::class) fun `it should …

Handling exceptions in tests: Junit & Kotest Read More »

Test execution basics: passed, failed, crashed

In Junit based testing framework there are few possible test outcomes: passed, failed and crashed. In this short note we will dive into that mechanisms. Test will pass, if no exception is thrown. Empty test should always pass: class TestFlowShowcase : StringSpec({ "it should pass"{ // nothing here }}) Or test with assertion that passes: …

Test execution basics: passed, failed, crashed Read More »

Assert softly – when one assertion is not enough

It’s usually in our best interest to keep one assertion per test method. Yet, situation when more than one check in single test method is present may occur. Why this may be a problem?Generally, JVM testing frameworks, such as Junit makes use of AssertionExceptions. If such exception is thrown during test block execution, test stops …

Assert softly – when one assertion is not enough Read More »

Building Unit Tests for ViewModel in TDD style

Your view model class usually has several functionalities. It somehow fetches data, it optionally maps your data entities to displayable entities, handles clicks and performs action for given events. You want to be sure that after refactor your code will still work perfectly. To achieve that you need to write and maintain unit tests. I …

Building Unit Tests for ViewModel in TDD style Read More »

KotlinUnitTesting – repository with examples

This repository contains examples of basic unit tests written in Kotlin. In specific directories you can find gradle buildscript with needed dependencies and configuration, simple unit test and parameterized test. rozkminiacz/KotlinUnitTesting Kotlin Unit Testing Examples. Contribute to rozkminiacz/KotlinUnitTesting development by creating an account on GitHub. GitHubrozkminiacz