Skip to content

Adds Testcontainers support for kotest(kotlintest)#2533

Closed
ashishkujoy wants to merge 21 commits intotestcontainers:masterfrom
ashishkujoy:master
Closed

Adds Testcontainers support for kotest(kotlintest)#2533
ashishkujoy wants to merge 21 commits intotestcontainers:masterfrom
ashishkujoy:master

Conversation

@ashishkujoy
Copy link

@ashishkujoy ashishkujoy commented Apr 6, 2020

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.

@bsideup bsideup changed the title Adds TestContainer support for kotest(kotlintest) Adds Testcontainers support for kotest(kotlintest) Apr 7, 2020
@ashishkujoy
Copy link
Author

@rnorth @bsideup @kiview Any feedback on this pull request?

internal class StartablePerSpecListener(private val startable: Startable) : TestListener {
override suspend fun beforeSpec(spec: Spec) {
withContext(Dispatchers.IO) {
startable.start()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TestLifecycleAware support is still missing...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please see other integrations

Copy link

@sksamuel sksamuel Apr 21, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Author

@ashishkujoy ashishkujoy Apr 21, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could store them in a variable in the beforeSpec callback.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

support added

Copy link
Member

@bsideup bsideup May 22, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ashishkujoy please do not resolve conversations started by others. e.g. this one remains unresolved, in fact.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

private fun TestCase.toTestDescription() = object : TestDescription {

override fun getFilesystemFriendlyName(): String {
return name.replace(" ", "-")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if name contains /, .. or similar characters?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For what purpose this FilesystemFriendlyName is used for?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

e.g. for writing video recordings captured from running a Chrome instance in the Selenium module

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will encoding the name will be ok like in SpockTestDescription?

@Override
String getFilesystemFriendlyName() {
return [specName, featureName].collect {
URLEncoder.encode(it, 'UTF-8')
}.join('-')
}

@sksamuel
Copy link

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.

@ashishkujoy
Copy link
Author

@bsideup could you please let me know what else we need to improve in this pull request

@rnorth
Copy link
Member

rnorth commented May 1, 2020

@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!

@ashishkujoy
Copy link
Author

@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.

@araujogo
Copy link

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

@bsideup
Copy link
Member

bsideup commented May 22, 2020

@araujogo FTR, there is nothing that prevents you from using Testcontainers with kotest straight away. In fact, in the current form, it is just a couple of lines.

As per @rnorth's comment, we're still evaluating how to proceed, stay tuned.

@ashishkujoy
Copy link
Author

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.

@ashishkujoy ashishkujoy closed this Jun 7, 2020
@kiview
Copy link
Member

kiview commented Jun 7, 2020

Thanks @ashishkujoy, very happy to see the implementation in Kotest repository.

@bsideup
Copy link
Member

bsideup commented Jun 7, 2020

@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 👍

@sksamuel
Copy link

sksamuel commented Jun 7, 2020 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants