assertions

Building assertions with Strikt

Strikt is assertion library built for Kotlin with API that allows building fluent assetions. To add library to project, add following dependency to your build.gradle repositories { mavenCentral()}dependencies { testImplementation("io.strikt:strikt-core:0.31.0")} To get latest version, visit Github Releases page: https://github.com/robfletcher/strikt/releases Basic usage Good assertion library should give us readable assertion errors. Strikt renders error in the …

Building assertions with Strikt Read More »

Testing time-based code with Joda Time

In some systems you sometimes need to record date or timestamp of given action. Good example could be comments system, where each comment has timestamp: interface CommentsInteractor { fun createComment(content: String): CommentEntity}data class CommentEntity( val content: String, val timestamp: Long) In our experiment we will perform two test cases: comment created at given time should …

Testing time-based code with Joda Time 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 »