kotest

Intro to testing Ktor controllers

Let’s suppose that we want to dismiss all calls for api/restricted endpoint if they don’t have special header, in this case „X-Special-Header”. We access header via get PipelineContext  and check if that value is null or blank. If so, we respond with HTTP 403. If given header is present,  we proceed with some business logic …

Intro to testing Ktor controllers 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 »

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 »