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
4
votes
1 answer

How to alter test object properties in KotlinTest via interceptTestCase

I am trying to use the interceptTestCase method to set up properties for a test case in KotlinTest as below: class MyTest : ShouldSpec() { private val items = mutableListOf() private var thing = 123 override fun…
Garth Gilmour
  • 11,124
  • 5
  • 25
  • 35
3
votes
2 answers

Kotest and kotlinx-coroutines-test Integration

I use the Funspec testing style in kotest and I get a coroutineScope injected automatically by the framework as shown below. class MyTestSpec: FunSpec() { init { test("test event loop") { mySuspendedFunction() // a…
rogue-one
  • 11,259
  • 7
  • 53
  • 75
3
votes
1 answer

How to verify a mock interface in a test method using KotlinTest library?

I have an interface that communicates with my presenter who checks whether the fields of a form are valid. My interface is: interface MainView { fun showMessage(data: LoginEntity) fun showEmailError() fun showPasswordError() } My method in…
beni
  • 3,019
  • 5
  • 35
  • 55
3
votes
2 answers

How to verify that a specific lambda method has been passed as argument with mockito

I have a Kotlin class (The problem was simplified to have a basic example), in it there is a method testedMethod() I want to test interactions on. I want to make sure the correct parameter is passed to anotherMethod(), my problem is that the…
Sebastian
  • 2,896
  • 23
  • 36
3
votes
1 answer

Kotlin, how to test (int)array

I'd like to find a nice and concise way to test intarray at first I tried mFaces[0].mIndices shouldBe intArrayOf(0, 1, 2) where mIndices is var mIndices: IntArray = IntArray(0) but fails. Intellij also suggests me to override equals() with…
elect
  • 6,765
  • 10
  • 53
  • 119
2
votes
2 answers

Assert that every object property matches given predicate in kotlin test

I have a collection of objects: data class WeatherForecast( val city: String, val forecast: String // ... ) I would like to test that each and every item matches given predicate on field. Is there any assertion in kotlintest assertions…
pixel
  • 24,905
  • 36
  • 149
  • 251
2
votes
1 answer

Kotest setup issue, 'unresolved reference'

I am trying to add kotest to my library, but am just getting: e: /home/brett/git/ttnt/src/test/kotlin/io/bmb/ttnt/lib/SqliteManagerTest.kt: (3, 18): Unresolved reference: specs e:…
Brett
  • 113
  • 3
  • 9
2
votes
2 answers

kotest nested spec in describe clause

I've started using kotest:4.0.5 (kotlintest) and having problem with stringSpec function nested in describe clause. Example: class SellerTest : DescribeSpec({ describe("Registration") { context("Not existing user") { …
MrNetroful
  • 497
  • 8
  • 28
2
votes
1 answer

Does Kotest (previously KotlinTest) still work in Android Studio?

As far as I can tell, Kotest requires JUnit 5: https://github.com/kotest/kotest/issues/1104 It also requires Gradle 6: https://github.com/kotest/kotest/issues/1301 I presume it's possible to get this all set up and working, but isn't it true that…
Tom B
  • 115
  • 8
2
votes
2 answers

How to run a single test in a context using kotest/kotlintest

I have the following test suite: class FooTest : FunSpec() { init { context("a context") { test("first test") { true shouldBe false } test("f:second test") { true…
u.sanyo
  • 47
  • 1
  • 7
2
votes
0 answers

Compare two strings and show results with diff - which allows to quickly spot the difference

When comparing two strings with #kotlintest with the test like this: "compare two strings" { "1: one\n2: two\n3: three".shouldBe("1: one1\n22: two\n3: three") } , the output looks like this: expected: "1: one1 22: two 3: three" but…
Maris
  • 664
  • 1
  • 5
  • 15
2
votes
1 answer

Autowire Spring TestEntityManager in Kotlintest not working

I am, as a learning experience, trying to port the tests described in Spring Boot's kotlin tutorial (https://spring.io/guides/tutorials/spring-boot-kotlin/) from using JUnit 5 to KotlinTest. In a repositories test annotated with @DataJpaTest, I…
Terje Andersen
  • 429
  • 2
  • 17
2
votes
3 answers

How to use MicronautTest with Kotlintest to inject beans while testing ? in Kotlin

How to inject the following into Test, as no constructor args are allowed and its failed to initialise the injected beans @MicronautTest class ApplicationTest:StringSpec() { @Inject lateinit val embeddedServer:EmbeddedServer; @Inject …
Swanand Keskar
  • 1,023
  • 1
  • 13
  • 27
2
votes
2 answers

How do you get rid of superfluous casts to implemented interface?

Let's say I have an interface public interface ICardSuit { /**short name*/ public String getName(); /** the colour of this card*/ public ICardColour getColour(); } that I decide to implement with an enum: public enum CardSuit…
User1291
  • 7,664
  • 8
  • 51
  • 108
2
votes
2 answers

How does kotlintest test spring boot application

The integration test of Spring boot application always starts the web server firstly. The simplest test of spring boot test looks like below, how does migrate it using kotlintest…
Kane
  • 8,035
  • 7
  • 46
  • 75