Questions tagged [kotlintest]

KotlinTest is open-source testing framework for Kotlin

Kotest is open-source testing framework for Kotlin: https://github.com/kotest/kotest/

82 questions
20
votes
2 answers

Is there Kotlin equivalent for AssertJ library?

I am converting some tests from Java to Kotlin. For Java tests I use AssertJ library which is very powerful and has rich set of assertions. My problem is that for Kotlin tests I can not use AssertJ and Kotlin JUnit…
Mario Kutlev
  • 4,897
  • 7
  • 44
  • 62
16
votes
5 answers

Intellij shows every line in build.gradle.kts is red

I created a new project from VCS (Kotlin and Gradle). I added three testImplementation() calls to the build.gradle.kts. IntelliJ didn't pickup the changes so I did File -> Invalidate caches / Restart and now Intellij shows every implementation()…
Dean Schulze
  • 9,633
  • 24
  • 100
  • 165
11
votes
1 answer

kotlin-test vs kotlin-test-junit

I have a kotlin project that is compiled to java. My test library is junit. Im using maven as my dependency management and Intellij IDEA. recently I got that strange warning in my pom. Inspection info: If you have kotlin-test and junit dependency…
yonBav
  • 1,695
  • 2
  • 17
  • 31
7
votes
3 answers

How to write beforeEach and beforeClass in kotlintest

Given is the example from kotlin-test github docs, but i don't see beforeEach or beforeClass concept here. I want to understand, How to execute a code/method once before every test How to execute a code/method once before every test class class…
JTeam
  • 1,455
  • 1
  • 11
  • 16
7
votes
3 answers

How to run kotlintest tests using the Gradle Kotlin DSL?

What do I want? I want to run my tests using kotlintest, and I succeeded in running them from IntelliJ by clicking the icon next to the test class. I also have JUnit 5 tests in my project. I am now starting to use the Gradle Kotlin DSL, and I…
PHPirate
  • 7,023
  • 7
  • 48
  • 84
7
votes
3 answers

How can I run kotlintest tests with gradle?

The kotlintest tests run perfectly fine when started from Intellij, but when I try to run them with the gradle test task command, only my regular JUnit tests are found and run. The kotlintest code: import io.kotlintest.matchers.shouldBe import…
Fabian
  • 1,982
  • 4
  • 25
  • 35
6
votes
1 answer

Kotlintest not executing test when using springmockk

I tried to write an integration test for my kotlin spring application. For this I am using the kotlintest framework. As I need to mock one of the beans in my application I also added mockk with the springmockk extension. After adding the springmockk…
JJensen
  • 86
  • 5
6
votes
2 answers

How can I initialize variable before each test using kotlin-test framework

I'm trying to find a way to set up variable before each test. Just like the @Before method in Junit. Go through the doc from kotlin-test, I found that I can use interceptTestCase() interface. But unfortunately, the code below will trigger…
Lawrence Ching
  • 423
  • 7
  • 16
6
votes
2 answers

What's the difference between shouldBe and shouldBe exactly in KotlinTest?

This is a test code using KotlinTest 1.3.5. val expect = 0.1 val actual: Double = getSomeDoubleValue() actual shouldBe expect and this warning was printed when the code was run. [WARN] When comparing doubles consider using tolerance, eg: a…
mmorihiro
  • 857
  • 2
  • 13
  • 17
5
votes
3 answers

NoClassDefFoundError when trying to execute JUnit 4 test in Intellij 2018.2.RC

When trying to execute a very simple Hello World test in Android, using KotlinTest: class ExampleUnitTest : FreeSpec() { init { "Test" { 2 + 2 shouldBe 4 } } } When trying to execute this in IntelliJ, by clicking the green icon,…
LeoColman
  • 6,950
  • 7
  • 34
  • 63
5
votes
2 answers

How do get kotlintest to work with Spring?

I'm trying to use kotlintest along with Spring (not Spring Boot, just the standard spring-test). I'm finding it very difficult to do. Any pointers as to what I am doing wrong? I am somewhat of a Kotlin newbie as well so I could very well not be…
Eric
  • 362
  • 1
  • 4
  • 15
4
votes
1 answer

How to test ViewModel + Flow with API call from init{}

I have ViewModel which exposes flow to fragment. I am calling API from ViewModel's init which emits different states. I am not able to write unit test to check all the emitted states. My ViewModel class FooViewModel constructor( fooProvider :…
DCoder
  • 3,486
  • 7
  • 36
  • 68
4
votes
1 answer

Is there a simpler way to test all permutations with Kotest property-based testing?

I'm working with kotlin + Kotest property testing and trying to test all permutations of 2 parameters with list generators like this: "Some test"{ forAll(4 , Exhaustive.collection(listOf( "a", …
janicedn
  • 53
  • 5
4
votes
2 answers

Data Table tests in Kotlintest - advanced method names and spreading of test cases

I am using Kotlintest and data tables to test an application that uses Kotlin, SpringBoot and Gradle because the syntax is way more concise than ParameterizedJunitTests when you have complex data in your tables. Is there a way to use the parameter…
peach
  • 657
  • 5
  • 26
4
votes
1 answer

Kotlin test, how to run BeforeEach with DescribeSpec test style

I'm trying to write KotlinTest tests running on JUnit5, with the Describe Spec style. When I need to initialize the same variable for some tests, @BeforeEach does not work inside DescribeSpec. How can initialize data before each test? class…
p3quod
  • 1,449
  • 3
  • 13
  • 15
1
2 3 4 5 6