-
Notifications
You must be signed in to change notification settings - Fork 631
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implemented beforeInvocation and afterInvocation hooks (#3589)
* implemented beforeInvocation hook * beforeInvocation - added to api * beforeInvocation - added docs * afterInvocation - added * Adjusting tests --------- Co-authored-by: Aleksey Yakovlev <aleksey.yakovlev@agoda.com> Co-authored-by: Emil Kantis <emil.kantis@protonmail.com>
- Loading branch information
1 parent
cf5537b
commit 7727acf
Showing
6 changed files
with
105 additions
and
2 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
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
33 changes: 33 additions & 0 deletions
33
...-junit5/src/jvmTest/kotlin/com/sksamuel/kotest/runner/junit5/InvokeAfterInvocationTest.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,33 @@ | ||
package com.sksamuel.kotest.runner.junit5 | ||
|
||
import io.kotest.core.spec.style.FunSpec | ||
import io.kotest.matchers.shouldBe | ||
import org.junit.platform.engine.discovery.DiscoverySelectors | ||
import org.junit.platform.testkit.engine.EngineTestKit | ||
|
||
class InvokeAfterInvocationTest : FunSpec({ | ||
test("should execute all afterInvocation blocks") { | ||
EngineTestKit.engine("kotest") | ||
.selectors(DiscoverySelectors.selectClass(AfterInvocationExample::class.java)) | ||
.configurationParameter("allow_private", "true") | ||
.execute() | ||
|
||
AfterInvocationExample.count shouldBe 30 | ||
} | ||
}) | ||
|
||
private class AfterInvocationExample : FunSpec() { | ||
|
||
companion object { | ||
var count = 0 | ||
} | ||
|
||
init { | ||
afterInvocation { _, _ -> count++ } // adds +1 10 times | ||
afterInvocation { _, _ -> count++ } // adds +1 10 times | ||
test("my case").config(invocations = 10) { | ||
count++ // adds +1 10 times | ||
true shouldBe true | ||
} // should be 30 in total | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
...junit5/src/jvmTest/kotlin/com/sksamuel/kotest/runner/junit5/InvokeBeforeInvocationTest.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,34 @@ | ||
package com.sksamuel.kotest.runner.junit5 | ||
|
||
import io.kotest.core.spec.style.FunSpec | ||
import io.kotest.matchers.shouldBe | ||
import org.junit.platform.engine.discovery.DiscoverySelectors | ||
import org.junit.platform.testkit.engine.EngineTestKit | ||
|
||
class InvokeBeforeInvocationTest : FunSpec({ | ||
test("should execute all beforeInvocation blocks") { | ||
EngineTestKit | ||
.engine("kotest") | ||
.selectors(DiscoverySelectors.selectClass(BeforeInvocationExample::class.java)) | ||
.configurationParameter("allow_private", "true") | ||
.execute() | ||
|
||
BeforeInvocationExample.count shouldBe 30 | ||
} | ||
}) | ||
|
||
private class BeforeInvocationExample : FunSpec() { | ||
|
||
companion object { | ||
var count = 0 | ||
} | ||
|
||
init { | ||
beforeInvocation { _, _ -> count++ } // adds +1 10 times | ||
beforeInvocation { _, _ -> count++ } // adds +1 10 times | ||
test("my case").config(invocations = 10) { | ||
count++ // adds +1 10 times | ||
true shouldBe true | ||
} // should be 30 in total | ||
} | ||
} |