Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/j5ik2o/scalatestplus-db
ScalaTest for MySQL and Flyway Support
https://github.com/j5ik2o/scalatestplus-db
flyway mysql scala scalatest
Last synced: 1 day ago
JSON representation
ScalaTest for MySQL and Flyway Support
- Host: GitHub
- URL: https://github.com/j5ik2o/scalatestplus-db
- Owner: j5ik2o
- License: mit
- Created: 2017-06-23T12:57:54.000Z (over 7 years ago)
- Default Branch: develop
- Last Pushed: 2023-12-15T02:46:47.000Z (11 months ago)
- Last Synced: 2024-05-02T01:17:17.857Z (6 months ago)
- Topics: flyway, mysql, scala, scalatest
- Language: Scala
- Homepage:
- Size: 68.4 KB
- Stars: 5
- Watchers: 3
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# scalatestplus-db
[![CircleCI](https://circleci.com/gh/j5ik2o/scalatestplus-db.svg?style=svg)](https://circleci.com/gh/j5ik2o/scalatestplus-db)
This library is a ScalaTest extension library that supports embedded MySQL and Flyway.
## Installation
Add the following to your sbt build (Scala 2.11.x, 2.12.x, 2.13.x):
### Release Version
```scala
resolvers ++= Seq(
"Seasar Repository" at "https://maven.seasar.org/maven2/",
Resolver.sonatypeRepo("releases")
)libraryDependencies += "com.github.j5ik2o" %% "scalatestplus-db" % ""
```### Snapshot Version
```scala
resolvers ++= Seq(
"Seasar Repository" at "https://maven.seasar.org/maven2/",
Resolver.sonatypeRepo("snapshots")
)libraryDependencies += "com.github.j5ik2o" %% "scalatestplus-db" % "-SNAPSHOT"
```## Usage
### When starting MySQLd for each test class
```scala
import com.wix.mysql.EmbeddedMysql
import org.scalatest.freespec.AnyFreeSpec
import org.scalatest.matchers.must.Matchersclass MySQLdOneInstancePerFreeSpec extends AnyFreeSpec with Matchers with MySQLdOneInstancePerSuite {
override protected val schemaConfigs: Seq[SchemaConfig] = Seq(SchemaConfig(name = "test"))
var mysqld: EmbeddedMysql = _
"MySQLdOneInstancePerFreeSpec" - {
"should start & stop mysqld1" in {
println(s"context = $mySQLdContext")
mySQLdContext mustNot be(null)
mySQLdContext.schemaConfigs.head.name mustBe "test"
mysqld = mySQLdContext.embeddedMysql
}
"should start & stop mysqld2" in {
println(s"context = $mySQLdContext")
mySQLdContext mustNot be(null)
mySQLdContext.schemaConfigs.head.name mustBe "test"
mySQLdContext.embeddedMysql mustBe mysqld
}
}}
```### When starting MySQLd for each test case
```scala
import com.wix.mysql.EmbeddedMysql
import org.scalatest.freespec.FixtureAnyFreeSpec
import org.scalatest.matchers.must.Matchersclass MySQLdOneInstancePerTestOfFreeSpec extends FixtureAnyFreeSpec with Matchers with MySQLdOneInstancePerTest {
override protected val schemaConfigs: Seq[SchemaConfig] = Seq(SchemaConfig(name = "test"))
var mysqld: EmbeddedMysql = _
"MySQLdOneInstancePerTestOfFreeSpec" - {
"should start & stop mysqld1" in { context =>
println(s"context = $context")
context mustNot be(null)
context.schemaConfigs.head.name mustBe "test"
mysqld = context.embeddedMysql
}
"should start & stop mysqld2" in { context =>
println(s"bbbb = $context")
context mustNot be(null)
context.schemaConfigs.head.name mustBe "test"
context.embeddedMysql mustNot be(mysqld)
}
}
}
```### When starting MySQLd with Flyway for each test class
```scala
import com.wix.mysql.EmbeddedMysql
import org.scalatest.freespec.AnyFreeSpec
import org.scalatest.matchers.must.Matchersclass FlywayWithMySQLdOneInstancePerFreeSpec
extends AnyFreeSpec
with Matchers
with FlywayWithMySQLdOneInstancePerSuite {override protected val schemaConfigs: Seq[SchemaConfig] = Seq(SchemaConfig(name = "test"))
override protected def flywayConfig(jdbcUrl: String): FlywayConfig = FlywayConfig(locations = Seq("db"))
var mysqld: EmbeddedMysql = _
"FlywayWithMySQLdOneInstancePerFreeSpec" - {
"should start & stop mysqld1" in {
println(s"context = $mySQLdContext")
mySQLdContext mustNot be(null)
mySQLdContext.schemaConfigs.head.name mustBe "test"
mysqld = mySQLdContext.embeddedMysql
}
"should start & stop mysqld2" in {
println(s"context = $mySQLdContext")
mySQLdContext mustNot be(null)
mySQLdContext.schemaConfigs.head.name mustBe "test"
mySQLdContext.embeddedMysql mustBe mysqld
}
}}
```### When starting MySQLd with Flyway for each test case
```scala
import com.wix.mysql.EmbeddedMysql
import org.scalatest.freespec.FixtureAnyFreeSpec
import org.scalatest.matchers.must.Matchersclass FlywayWithMySQLdOneInstancePerTestOfFreeSpec
extends FixtureAnyFreeSpec
with Matchers
with FlywayWithMySQLdOneInstancePerTest {override protected val schemaConfigs: Seq[SchemaConfig] = Seq(SchemaConfig(name = "test"))
override protected def flywayConfig(jdbcUrl: String): FlywayConfig = FlywayConfig(locations = Seq("db"))
var mysqld: EmbeddedMysql = _
"FlywayWithMySQLdOneInstancePerTestOfFreeSpec" - {
"should start & stop mysqld1" in { context =>
println(s"context = $context")
context.mySQLdContext mustNot be(null)
context.mySQLdContext.schemaConfigs.head.name mustBe "test"
mysqld = context.mySQLdContext.embeddedMysql
}
"should start & stop mysqld2" in { context =>
println(s"context = $context")
context.mySQLdContext mustNot be(null)
context.mySQLdContext.schemaConfigs.head.name mustBe "test"
context.mySQLdContext.embeddedMysql mustNot be(mysqld)
}
}}
```