Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create alternative way to use testcontainers in MUnit using fixtures #214

Merged
merged 3 commits into from
Mar 15, 2022
Merged

Create alternative way to use testcontainers in MUnit using fixtures #214

merged 3 commits into from
Mar 15, 2022

Conversation

alejandrohdezma
Copy link
Contributor

@alejandrohdezma alejandrohdezma commented Mar 14, 2022

🚀 What is included in this PR?

This PR includes an alternative way (more idiomatic) of using TestContainers with MUnit using fixtures.

Some examples:

class MysqlSpec extends FunSuite with TestContainersFixtures {

  val mysql = ForEachContainerFixture(MySQLContainer())

  // You need to override `munitFixtures` and pass in your container fixture
  override def munitFixtures = List(mysql)

  test("test case name") {
    // Inside your test body you can do with your container whatever you want to
    assert(mysql.container.jdbcUrl.nonEmpty)
  }
}
class MysqlSpec extends FunSuite with TestContainersFixtures {

  val mysql = ForAllContainerFixture(MySQLContainer())

  // You need to override `munitFixtures` and pass in your container fixture
  override def munitFixtures = List(mysql)

  test("test case name") {
    // Inside your test body you can do with your container whatever you want to
    assert(mysql.container.jdbcUrl.nonEmpty)
  }
}
class MysqlSpec extends FunSuite with TestContainersFixtures {
 
  val mysql = ContainerFunFixture(MySQLContainer())
 
  mysql.test("test case name") { container =>
    // Inside your test body you can do with your container whatever you want to
    assert(container.jdbcUrl.nonEmpty)
  }
}

@dimafeng
Copy link
Collaborator

@alejandrohdezma thank you so much! This looks great!

Would you mind adding a few examples to the readme?

@alejandrohdezma
Copy link
Contributor Author

@dimafeng Done! 😸

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.

2 participants