-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MicronautKotest5Extension now cleans up contexts after test spec is d…
…one (#868)
- Loading branch information
1 parent
666214c
commit 2b3c5ef
Showing
3 changed files
with
53 additions
and
16 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
29 changes: 29 additions & 0 deletions
29
test-kotest5/src/test/kotlin/io/micronaut/test/kotest5/NoContextsRetentionTest.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,29 @@ | ||
package io.micronaut.test.kotest5 | ||
|
||
import io.kotest.core.spec.style.FunSpec | ||
import io.kotest.matchers.collections.shouldHaveSize | ||
import io.kotest.matchers.nulls.shouldBeNull | ||
import io.kotest.matchers.nulls.shouldNotBeNull | ||
import io.micronaut.test.extensions.kotest5.MicronautKotest5Extension | ||
import io.micronaut.test.extensions.kotest5.annotation.MicronautTest | ||
|
||
class NoContextsRetentionTest : FunSpec({ | ||
test("extension should not retain references to contexts after tests are finished") { | ||
MicronautKotest5Extension.contexts[NoContextsRetentionTests::class.java.name].shouldBeNull() | ||
val a = MicronautKotest5Extension.instantiate(NoContextsRetentionTests::class).shouldNotBeNull() | ||
val b = MicronautKotest5Extension.instantiate(NoContextsRetentionTests::class).shouldNotBeNull() | ||
MicronautKotest5Extension.contexts[NoContextsRetentionTests::class.java.name].shouldNotBeNull().shouldHaveSize(2) | ||
MicronautKotest5Extension.afterSpec(a) | ||
MicronautKotest5Extension.contexts[NoContextsRetentionTests::class.java.name].shouldNotBeNull().shouldHaveSize(1) | ||
MicronautKotest5Extension.afterSpec(b) | ||
MicronautKotest5Extension.contexts[NoContextsRetentionTests::class.java.name].shouldBeNull() | ||
} | ||
}) | ||
|
||
@MicronautTest | ||
// need a parameter here so the extension instantiates the spec | ||
private class NoContextsRetentionTests(private val mathService: MathService) : FunSpec() { | ||
init { | ||
test("test1") {} | ||
} | ||
} |