Adds Testcontainers support for kotest(kotlintest)#2533
Adds Testcontainers support for kotest(kotlintest)#2533ashishkujoy wants to merge 21 commits intotestcontainers:masterfrom ashishkujoy:master
Conversation
modules/kotest/src/main/kotlin/org/testcontainers/containers/ContainerPerTestListener.kt
Outdated
Show resolved
Hide resolved
modules/kotest/src/main/kotlin/org/testcontainers/containers/ContainerPerSpecListener.kt
Outdated
Show resolved
Hide resolved
…r from java docs comment
… in examples/kotest module
.../examples/kotest/src/test/kotlin/com/example/kotest/TestContainerKotestIntegrationPerTest.kt
Outdated
Show resolved
Hide resolved
.../examples/kotest/src/test/kotlin/com/example/kotest/TestContainerKotestIntegrationPerTest.kt
Outdated
Show resolved
Hide resolved
.../examples/kotest/src/test/kotlin/com/example/kotest/TestcontainerKotestIntegrationPerSpec.kt
Outdated
Show resolved
Hide resolved
modules/kotest/src/main/kotlin/org/testcontainers/containers/ContainerPerTestListener.kt
Outdated
Show resolved
Hide resolved
modules/kotest/src/test/kotlin/org/testcontainers/containers/ContainerPerSpecListenerTest.kt
Outdated
Show resolved
Hide resolved
…r creating listener from container
...otest/src/test/kotlin/org/testcontainers/containers/TestcontainerKotestIntegrationPerSpec.kt
Outdated
Show resolved
Hide resolved
modules/kotest/src/main/kotlin/org/testcontainers/containers/StartablePerSpecListener.kt
Outdated
Show resolved
Hide resolved
modules/kotest/src/main/kotlin/org/testcontainers/containers/StartablePerSpecListener.kt
Outdated
Show resolved
Hide resolved
modules/kotest/src/main/kotlin/org/testcontainers/containers/StartablePerSpecListener.kt
Outdated
Show resolved
Hide resolved
modules/kotest/src/main/kotlin/org/testcontainers/containers/StartablePerSpecListener.kt
Outdated
Show resolved
Hide resolved
modules/kotest/src/main/kotlin/org/testcontainers/containers/StartablePerTestListener.kt
Outdated
Show resolved
Hide resolved
...otest/src/test/kotlin/org/testcontainers/containers/TestContainerKotestIntegrationPerTest.kt
Outdated
Show resolved
Hide resolved
…rSpecListener as that causes compilation errors
…and start-stop startable in IO coroutine context
modules/kotest/src/main/kotlin/org/testcontainers/containers/Extensions.kt
Outdated
Show resolved
Hide resolved
…s in per test listener
| internal class StartablePerSpecListener(private val startable: Startable) : TestListener { | ||
| override suspend fun beforeSpec(spec: Spec) { | ||
| withContext(Dispatchers.IO) { | ||
| startable.start() |
There was a problem hiding this comment.
TestLifecycleAware support is still missing...
There was a problem hiding this comment.
TestLifecycleAware has two methods beforeTest and afterTest, as whereas SpecListener are for runnig before and after the entire spec(Test class). Thats the reason i have not added it there.
There was a problem hiding this comment.
@ashishkujoy As I understand it, if the startable is a TestLifecycleAware, then we should call beforeTest and afterTest on it, as the container may need to do "other things" between tests, even if we're registering it on the spec (class) level.
There was a problem hiding this comment.
The documentation needs to be corrected:
This should be use when you want to a single container for all test in a single test class.
to
This listener should be used when you want to use a single container for all tests in a single spec class.
There was a problem hiding this comment.
@sksamuel That would be difficult because the before and after test functions in TestLifecylceAware takes TestDescription as parameter which in itself needs testId and testName and these informations are not present in Spec class which we receive in beforeSpec and afterSpec callback.
There was a problem hiding this comment.
You could store them in a variable in the beforeSpec callback.
There was a problem hiding this comment.
@ashishkujoy please do not resolve conversations started by others. e.g. this one remains unresolved, in fact.
There was a problem hiding this comment.
That would be difficult because the before and after test functions in TestLifecylceAware takes TestDescription as parameter which in itself needs testId and testName and these informations are not present in Spec class which we receive in beforeSpec and afterSpec callback.
something to improve in kotest? Other test frameworks don't have this problem.
modules/kotest/src/main/kotlin/org/testcontainers/containers/StartablePerTestListener.kt
Outdated
Show resolved
Hide resolved
| private fun TestCase.toTestDescription() = object : TestDescription { | ||
|
|
||
| override fun getFilesystemFriendlyName(): String { | ||
| return name.replace(" ", "-") |
There was a problem hiding this comment.
what if name contains /, .. or similar characters?
There was a problem hiding this comment.
For what purpose this FilesystemFriendlyName is used for?
There was a problem hiding this comment.
e.g. for writing video recordings captured from running a Chrome instance in the Selenium module
There was a problem hiding this comment.
Will encoding the name will be ok like in SpockTestDescription?
modules/kotest/src/test/kotlin/org/testcontainers/containers/TestLifecycleAwareTest.kt
Outdated
Show resolved
Hide resolved
|
How close are we on this PR? I'd love to start using it. At the moment I'm having to roll my own support. |
|
@bsideup could you please let me know what else we need to improve in this pull request |
|
@ashishkujoy please hold tight; as you can see we have quite a few other PRs to review. Also this one needs more careful consideration than most: adding a new language to our build is not a small thing for those of us who will have to maintain it. We'll get back to you! |
Agreed, thanks for reply. |
|
Looking forward to use this as my colleagues and I are migrating all of our services to kotlin and using kotest. I suggest giving this PR an extra attention as it`s a switch that would give support to lots of kotlin devs, of a very increasing community |
|
Closing this pull request as we have now merged the kotest-extensions-testcontainers support in Kotest repository. Thanks @bsideup @kiview @sksamuel for your valuable guidance in this pull request. |
|
Thanks @ashishkujoy, very happy to see the implementation in Kotest repository. |
|
@ashishkujoy wow, very cool! I believe keeping it closer to the framework will allow you to have it very aligned with framework's ideas and future new APIs 👍 |
|
Should we open a pr to add a link in the docs?
…On Sun, 7 Jun 2020, 04:14 Sergei Egorov, ***@***.***> wrote:
@ashishkujoy <https://github.com/ashishkujoy> wow, very cool! I believe
keeping it closer to the framework will allow you to have it very aligned
with framework's ideas and future new APIs 👍
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#2533 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAFVSGRYNQPMKNIK4ZFPEVDRVNK65ANCNFSM4MCRL7IQ>
.
|
Kotest previously known kotlintest is a widely used test framework for kotlin. This commit add test container support for kotest by providing TestListeners implementation to hookup test container with test lifecycle.