本文整理汇总了Scala中org.scalatest.TestSuite类的典型用法代码示例。如果您正苦于以下问题:Scala TestSuite类的具体用法?Scala TestSuite怎么用?Scala TestSuite使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TestSuite类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: start
//设置package包名称以及导入依赖的类
package io.scalatestfx.framework.scalatest
import javafx.stage.Stage
import org.scalatest.Outcome
import org.scalatest.TestSuite
import org.scalatest.TestSuiteMixin
import org.testfx.api.FxToolkit
import io.scalatestfx.api.Java8Conversions._
trait ApplicationFixture extends TestSuiteMixin { self: TestSuite =>
def start(stage: Stage): Unit
def init() {
FxToolkit.registerStage(asSupplier(() => {
new Stage()
}))
}
def stop() {
FxToolkit.hideStage()
}
abstract override def withFixture(test: NoArgTest): Outcome = {
val superWithFixture = super.withFixture _ // required to access to super withFixture method from within runnable for a trait
//setup before all tests
FxToolkit.registerPrimaryStage()
FxToolkit.setupApplication(() => {
new ApplicationAdapter(ApplicationFixture.this)
})
val outcome = superWithFixture(test)
//cleanup after all tests
FxToolkit.cleanupApplication(new ApplicationAdapter(ApplicationFixture.this))
outcome
}
}
示例2: start
//设置package包名称以及导入依赖的类
package io.scalatestfx.framework.scalatest
import javafx.{stage => jfxst}
import org.scalatest.Outcome
import org.scalatest.TestSuite
import org.scalatest.TestSuiteMixin
import org.testfx.api.FxToolkit
import scalafx.stage.Stage
import io.scalatestfx.api.Java8Conversions._
trait JFXAppFixture extends TestSuiteMixin { self: TestSuite =>
def start(stage: Stage): Unit
def init() {
FxToolkit.registerStage(asSupplier(() => {
new jfxst.Stage()
}))
}
def stop(): Unit = {}
abstract override def withFixture(test: NoArgTest): Outcome = {
val superWithFixture = super.withFixture _ // required to access to super withFixture method from within runnable for a trait
//setup before all tests
FxToolkit.registerPrimaryStage()
FxToolkit.setupApplication(() => {
new JFXAppAdapter(JFXAppFixture.this)
})
val outcome = superWithFixture(test)
//cleanup after all tests
FxToolkit.cleanupApplication(new JFXAppAdapter(JFXAppFixture.this))
outcome
}
}
示例3: withFixture
//设置package包名称以及导入依赖的类
package io.scalatestfx.zzznolongerused
import java.util.concurrent.CountDownLatch
import javafx.application.Platform
import org.scalatest.{Outcome, TestSuite, TestSuiteMixin}
trait RunOnApplicationThread extends TestSuiteMixin {
this: TestSuite =>
abstract override def withFixture(test: NoArgTest): Outcome = {
BootstrapApplication.launch()
val appThreadLatch = new CountDownLatch(1)
val superWith = super.withFixture _ // required to access to super withFixture method from within runnable for a trait
var testException: Exception = null
var outcome: Outcome = null
Platform.runLater(new Runnable() {
override def run() {
try {
outcome = superWith(test)
} catch {
case e: Exception => testException = e
} finally {
appThreadLatch.countDown()
}
}
})
appThreadLatch.await()
if (testException != null) {
throw testException
}
outcome
}
}
示例4: flywayContexts
//设置package包名称以及导入依赖的类
package com.github.j5ik2o.scalatestplus.db
import org.flywaydb.core.internal.util.jdbc.DriverDataSource
import org.scalatest.{ Args, Status, TestSuite, TestSuiteMixin }
trait FlywayWithMySQLdOneInstancePerSuite extends FlywayOneInstancePerSuiteBase with MySQLdOneInstancePerSuite {
this: TestSuite =>
}
trait FlywayOneInstancePerSuiteBase extends TestSuiteMixin with FlywaySpecSupport {
this: TestSuite with MySQLdOneInstancePerSuite =>
private var _contexts: Seq[FlywayContext] = _
protected def flywayContexts: Seq[FlywayContext] = _contexts
protected def flywayConfig(jdbcUrl: String): FlywayConfig
protected def flywayConfigWithDataSources: Seq[FlywayConfigWithDataSource] = mySQLdContext.jdbUrls.map { jdbcUrl =>
FlywayConfigWithDataSource(
new DriverDataSource(
getClass.getClassLoader,
MY_SQL_JDBC_DRIVER_NAME,
jdbcUrl,
mySQLdContext.userName,
mySQLdContext.password
),
flywayConfig(jdbcUrl)
)
}
protected def flywayMigrate(flywayContext: FlywayContext): Int =
flywayContext.flyway.migrate()
protected def flywayClean(flywayContext: FlywayContext): Unit =
flywayContext.flyway.clean()
abstract override def run(testName: Option[String], args: Args): Status = {
try {
_contexts = flywayConfigWithDataSources.map { flywayConfig =>
val flywayContext = createFlywayContext(flywayConfig)
flywayMigrate(flywayContext)
flywayContext
}
val status = super.run(testName, args)
status.whenCompleted { _ =>
if (_contexts != null)
_contexts.foreach(flywayClean)
}
status
} catch {
case ex: Throwable =>
if (_contexts != null)
_contexts.foreach(flywayClean)
throw ex
}
}
}
示例5: mySQLdContext
//设置package包名称以及导入依赖的类
package com.github.j5ik2o.scalatestplus.db
import org.scalatest.{ Args, Status, TestSuite, TestSuiteMixin }
trait MySQLdOneInstancePerSuite extends TestSuiteMixin with MySQLdSpecSupport { this: TestSuite =>
private var _context: MySQLdContext = _
protected def mySQLdContext: MySQLdContext = _context
abstract override def run(testName: Option[String], args: Args): Status = {
try {
_context = startMySQLd(mySQLdConfig = MySQLdConfig(port = Some(RandomSocket.temporaryServerPort())))
val status = super.run(testName, args)
status.whenCompleted { _ =>
if (_context != null)
stopMySQLd(_context)
}
status
} catch {
case ex: Throwable =>
if (_context != null)
stopMySQLd(_context)
throw ex
}
}
}
示例6: withFixture
//设置package包名称以及导入依赖的类
package servicetest.helpers
import java.io.File
import com.machinepublishers.jbrowserdriver.{JBrowserDriver, Settings, Timezone}
import org.apache.commons.io.FileUtils
import org.openqa.selenium.OutputType.BYTES
import org.openqa.selenium.{TakesScreenshot, WebDriver}
import org.scalatest.selenium.WebBrowser
import org.scalatest.{Outcome, TestSuite}
trait BrowserTesting extends TestSuite with WebBrowser {
implicit val webDriver: WebDriver = new JBrowserDriver(Settings.builder().timezone(Timezone.UTC).build())
private val testScreenshotsDir = sys.env.getOrElse("CIRCLE_ARTIFACTS", "target/screenshots")
override protected def withFixture(test: NoArgTest): Outcome = {
val outcome = test()
if (outcome.isExceptional) {
webDriver match {
case driver: TakesScreenshot =>
val bytes = driver.getScreenshotAs(BYTES)
FileUtils.writeByteArrayToFile(new File(s"$testScreenshotsDir/${test.name}.png"), bytes)
}
}
outcome
}
}
示例7: AppWithTestComponents
//设置package包名称以及导入依赖的类
import helpers.{
OneAppPerSuiteWithComponents,
OneAppPerTestWithComponents,
OneServerPerSuiteWithComponents,
OneServerPerTestWithComponents
}
import org.scalatest.TestSuite
import play.api.ApplicationLoader.Context
import play.api.libs.ws.ahc.AhcWSComponents
import wiring.AppComponents
class AppWithTestComponents(context: Context)
extends AppComponents(context)
with AhcWSComponents
trait OneAppPerTestWithMyComponents
extends OneAppPerTestWithComponents[AppWithTestComponents] {
this: TestSuite =>
override def createComponents(context: Context) =
new AppWithTestComponents(context)
}
trait OneAppPerSuiteWithMyComponents
extends OneAppPerSuiteWithComponents[AppWithTestComponents] {
this: TestSuite =>
override def createComponents(context: Context) =
new AppWithTestComponents(context)
}
trait OneServerPerTestWithMyComponents
extends OneServerPerTestWithComponents[AppWithTestComponents] {
this: TestSuite =>
override def createComponents(context: Context) =
new AppWithTestComponents(context)
}
trait OneServerPerSuiteWithMyComponents
extends OneServerPerSuiteWithComponents[AppWithTestComponents] {
this: TestSuite =>
override def createComponents(context: Context) =
new AppWithTestComponents(context)
}
示例8: components
//设置package包名称以及导入依赖的类
package helpers
import org.scalatest.TestSuite
import org.scalatestplus.play._
import play.api.{BuiltInComponents, _}
import play.api.ApplicationLoader.Context
import play.api._
trait OneAppPerTestWithComponents[T <: BuiltInComponents]
extends BaseOneAppPerTest
with FakeApplicationFactory
with WithApplicationComponents[T] { this: TestSuite =>
}
trait OneAppPerSuiteWithComponents[T <: BuiltInComponents]
extends BaseOneAppPerSuite
with FakeApplicationFactory
with WithApplicationComponents[T] { this: TestSuite =>
}
trait OneServerPerTestWithComponents[T <: BuiltInComponents]
extends BaseOneServerPerTest
with FakeApplicationFactory
with WithApplicationComponents[T] { this: TestSuite =>
}
trait OneServerPerSuiteWithComponents[T <: BuiltInComponents]
extends BaseOneServerPerSuite
with FakeApplicationFactory
with WithApplicationComponents[T] { this: TestSuite =>
}
trait WithApplicationComponents[T <: BuiltInComponents] {
private var _components: T = _
// accessed to get the components in tests
final def components: T = _components
// overridden by subclasses
def createComponents(context: Context): T
// creates a new application and sets the components
def fakeApplication(): Application = {
_components = createComponents(context)
_components.application
}
def context: ApplicationLoader.Context = {
val classLoader = ApplicationLoader.getClass.getClassLoader
val env = new Environment(new java.io.File("."), classLoader, Mode.Test)
ApplicationLoader.createContext(env)
}
}
示例9: flywayConfig
//设置package包名称以及导入依赖的类
package com.github.j5ik2o.scala.ddd.functional.slick.test
import java.io.File
import com.github.j5ik2o.scalatestplus.db._
import org.scalatest.TestSuite
trait FlywayWithMySQLSpecSupport extends FlywayWithMySQLdOneInstancePerSuite with RandomPortSupport {
this: TestSuite =>
override protected lazy val mySQLdConfig: MySQLdConfig = MySQLdConfig(
port = Some(temporaryServerPort()),
userWithPassword = Some(UserWithPassword("free", "passwd"))
)
override protected lazy val downloadConfig: DownloadConfig =
super.downloadConfig.copy(cacheDir = new File(sys.env("HOME") + "/.wixMySQL/downloads"))
override protected lazy val schemaConfigs: Seq[SchemaConfig] = Seq(SchemaConfig(name = "free"))
override protected def flywayConfig(jdbcUrl: String): FlywayConfig =
FlywayConfig(
locations = Seq("db/migration/default"),
placeholderConfig =
Some(PlaceholderConfig(placeholderReplacement = true, placeholders = Map("engineName" -> "MEMORY")))
)
}
示例10: patienceConfig
//设置package包名称以及导入依赖的类
package com.github.j5ik2o.scala.ddd.functional.slick
import com.github.j5ik2o.scala.ddd.functional.slick.test.FlywayWithMySQLSpecSupport
import com.typesafe.config.ConfigFactory
import org.scalatest.TestSuite
import org.scalatest.concurrent.ScalaFutures
import org.scalatest.time.{ Millis, Seconds, Span }
import slick.basic.DatabaseConfig
import slick.jdbc.JdbcProfile
import scala.concurrent.ExecutionContext
trait Slick3SpecSupport extends ScalaFutures { this: TestSuite with FlywayWithMySQLSpecSupport =>
override implicit def patienceConfig: PatienceConfig =
PatienceConfig(timeout = scaled(Span(5, Seconds)), interval = scaled(Span(15, Millis)))
private var _dbConfig: DatabaseConfig[JdbcProfile] = _
private var _profile: JdbcProfile = _
private var _ec: ExecutionContext = _
def jdbcPort: Int = mySQLdConfig.port.get
protected def dbConfig = _dbConfig
protected def profile = _profile
implicit def ec: ExecutionContext = _ec
def startSlick(): Unit = {
val config = ConfigFactory.parseString(s"""
|free {
| profile = "slick.jdbc.MySQLProfile$$"
| db {
| connectionPool = disabled
| driver = "com.mysql.jdbc.Driver"
| url = "jdbc:mysql://localhost:$jdbcPort/free?useSSL=false"
| user = "free"
| password = "passwd"
| }
|}
""".stripMargin)
_dbConfig = DatabaseConfig.forConfig[JdbcProfile]("free", config)
_profile = dbConfig.profile
_ec = dbConfig.db.executor.executionContext
}
def stopSlick(): Unit = {
dbConfig.db.shutdown
}
}
示例11: patienceConfig
//设置package包名称以及导入依赖的类
package com.github.j5ik2o.scala.ddd.functional.skinnyorm
import com.github.j5ik2o.scala.ddd.functional.slick.test.FlywayWithMySQLSpecSupport
import org.scalatest.TestSuite
import org.scalatest.concurrent.ScalaFutures
import org.scalatest.time.{ Millis, Seconds, Span }
import scalikejdbc._
trait SkinnyORMSpecSupport extends ScalaFutures { this: TestSuite with FlywayWithMySQLSpecSupport =>
override implicit def patienceConfig: PatienceConfig =
PatienceConfig(timeout = scaled(Span(5, Seconds)), interval = scaled(Span(15, Millis)))
GlobalSettings.loggingSQLAndTime = LoggingSQLAndTimeSettings(
enabled = true,
logLevel = 'DEBUG,
warningEnabled = true,
warningThresholdMillis = 1000L,
warningLogLevel = 'WARN
)
def startSkinnyORM(): Unit = {
Class.forName("com.mysql.jdbc.Driver")
val jdbcUrl = mySQLdContext.jdbUrls.head
val userName = mySQLdContext.userName
val password = mySQLdContext.password
ConnectionPool.singleton(
jdbcUrl,
userName,
password
)
}
def stopSkinnyORM(): Unit = {
ConnectionPool.close()
}
}