Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed issues 1435 Add before and after test listeners to property ba… (…
…#1452) * Fixed issues 1435 Add before and after test listeners to property base tests. #1435 * Issue 1435 Change the listeners list to be immutable. #1435 Co-authored-by: Atara Shachar <ashachar@atlassian.com>
- Loading branch information
1 parent
21a88b1
commit f4044cd
Showing
3 changed files
with
149 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
126 changes: 126 additions & 0 deletions
126
kotest-property/src/jvmTest/kotlin/com/sksamuel/kotest/property/PropListenersTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
package com.sksamuel.kotest.property | ||
|
||
import io.kotest.core.spec.style.FunSpec | ||
import io.kotest.matchers.shouldBe | ||
import io.kotest.matchers.shouldNotBe | ||
import io.kotest.property.* | ||
import io.kotest.property.arbitrary.int | ||
import io.kotest.property.arbitrary.string | ||
|
||
class PropListenersTest : FunSpec({ | ||
var previous = -1 | ||
var current = 0 | ||
var total = 0 | ||
|
||
beforeTest { | ||
previous = -1 | ||
current = 0 | ||
total = 0 | ||
} | ||
|
||
val propConfig = PropTestConfig(listeners = listOf(object : PropTestListener { | ||
override suspend fun beforeTest() { | ||
previous = current | ||
++current | ||
} | ||
|
||
override suspend fun afterTest() { | ||
++total | ||
} | ||
})) | ||
|
||
test("checkAll calls listener for param A") { | ||
val context = checkAll(10, propConfig, Arb.string()) { | ||
current shouldBe (previous + 1) | ||
total shouldBe previous | ||
} | ||
previous shouldBe 9 | ||
current shouldBe 10 | ||
total shouldBe 10 | ||
} | ||
|
||
test("checkAll calls listener for params A, B") { | ||
val context = checkAll( | ||
10, | ||
propConfig, | ||
Arb.string(), | ||
Arb.int() | ||
) { _, _ -> | ||
current shouldBe (previous + 1) | ||
total shouldBe previous | ||
} | ||
previous shouldBe 9 | ||
current shouldBe 10 | ||
total shouldBe 10 | ||
} | ||
|
||
test("checkAll calls listener for params A, B, C") { | ||
val context = checkAll( | ||
10, | ||
propConfig, | ||
Arb.string(), | ||
Arb.string(), | ||
Arb.int() | ||
) { _, _, _ -> | ||
current shouldBe (previous + 1) | ||
total shouldBe previous | ||
} | ||
previous shouldBe 9 | ||
current shouldBe 10 | ||
total shouldBe 10 | ||
} | ||
|
||
test("checkAll calls listener for params A, B, C, D") { | ||
val context = checkAll( | ||
10, | ||
propConfig, | ||
Arb.string(), | ||
Arb.int(), | ||
Arb.string(), | ||
Arb.int() | ||
) { _, _, _, _ -> | ||
current shouldBe (previous + 1) | ||
total shouldBe previous | ||
} | ||
previous shouldBe 9 | ||
current shouldBe 10 | ||
total shouldBe 10 | ||
} | ||
|
||
test("checkAll calls listener for params A, B, C, D, E") { | ||
val context = checkAll( | ||
10, | ||
propConfig, | ||
Arb.string(), | ||
Arb.int(), | ||
Arb.string(), | ||
Arb.string(), | ||
Arb.int() | ||
) { _, _, _, _, _ -> | ||
current shouldBe (previous + 1) | ||
total shouldBe previous | ||
} | ||
previous shouldBe 9 | ||
current shouldBe 10 | ||
total shouldBe 10 | ||
} | ||
|
||
test("checkAll calls listener for params A, B, C, D, E, F") { | ||
val context = checkAll( | ||
10, | ||
propConfig, | ||
Arb.string(), | ||
Arb.int(), | ||
Arb.string(), | ||
Arb.int(), | ||
Arb.string(), | ||
Arb.int() | ||
) { _, _, _, _, _, _ -> | ||
current shouldBe (previous + 1) | ||
total shouldBe previous | ||
} | ||
previous shouldBe 9 | ||
current shouldBe 10 | ||
total shouldBe 10 | ||
} | ||
}) |