本文整理汇总了Scala中org.scalatest.Outcome类的典型用法代码示例。如果您正苦于以下问题:Scala Outcome类的具体用法?Scala Outcome怎么用?Scala Outcome使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Outcome类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: TestFixture
//设置package包名称以及导入依赖的类
package cz.alenkacz.marathon.scaler
import com.rabbitmq.client._
import cz.alenkacz.marathon.scaler.rabbitmq.Client
import org.scalatest.{Matchers, Outcome}
abstract class TestFixture
extends org.scalatest.fixture.FlatSpec
with Matchers {
case class FixtureParam(rmqClients: Map[String, TestClient])
case class TestClient(channel: Channel,
apiUrl: String,
username: String,
password: String)
extends Client(apiUrl, username, password) {
def prepareTopology(): Unit = {
channel.queueDeclare("test", true, false, false, null)
channel.confirmSelect()
}
def close(): Unit = channel.close()
}
override protected def withFixture(test: OneArgTest): Outcome = {
val fixture = FixtureParam(
Map(
"" -> TestClient(
rmqConnect(System.getenv("RABBITMQ_HOST"),
Integer.parseInt(System.getenv("RABBITMQ_TCP_5672"))),
s"http://${System.getenv("RABBITMQ_HOST")}:${System.getenv("RABBITMQ_TCP_15672")}/api/",
"guest",
"guest"
),
"second" -> TestClient(
rmqConnect(
System.getenv("RABBITMQ-SECOND_HOST"),
Integer.parseInt(System.getenv("RABBITMQ-SECOND_TCP_5672"))),
s"http://${System.getenv("RABBITMQ-SECOND_HOST")}:${System.getenv("RABBITMQ-SECOND_TCP_15672")}/api/",
"guest",
"guest"
)
))
fixture.rmqClients.values.foreach(c => c.prepareTopology())
try super.withFixture(test.toNoArgTest(fixture))
finally {
fixture.rmqClients.values.foreach(c => c.close())
}
}
private def rmqConnect(host: String, port: Int): Channel = {
val rmqConnectionFactory: ConnectionFactory = {
val factory = new ConnectionFactory()
factory.setAutomaticRecoveryEnabled(true)
factory.setVirtualHost("/")
factory.setHost(host)
factory.setPort(port)
factory
}
rmqConnectionFactory.newConnection().createChannel()
}
}
示例2: 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
}
}
示例3: 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
}
}
示例4: 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
}
}
示例5: SerializationSpec
//设置package包名称以及导入依赖的类
package de.sciss.fscape
import de.sciss.fscape.lucre.FScape
import de.sciss.lucre.expr.DoubleObj
import de.sciss.lucre.stm.Durable
import de.sciss.lucre.stm.store.BerkeleyDB
import de.sciss.synth.proc.SoundProcesses
import org.scalatest.{Matchers, Outcome, fixture}
class SerializationSpec extends fixture.FlatSpec with Matchers {
type S = Durable
type FixtureParam = S
SoundProcesses.init()
FScape .init()
protected def withFixture(test: OneArgTest): Outcome = {
val store = BerkeleyDB.tmp()
val system = Durable(store)
try {
test(system)
} finally {
system.close()
}
}
"An FScape object" should "be serializable" in { cursor =>
val (fH, numSources) = cursor.step { implicit tx =>
val f = FScape[S]
val g = Graph {
import graph._
import lucre.graph._
1.poll(0, label = "rendering")
val value = WhiteNoise(100).take(100000000).last
MkDouble("out-1", value)
MkDouble("out-2", value + 1)
}
f.outputs.add("out-2", DoubleObj)
f.graph() = g
tx.newHandle(f) -> g.sources.size
}
cursor.step { implicit tx =>
val f = fH()
val g = f.graph.value
assert(g.sources.size === numSources)
val outputs = f.outputs.iterator.toList.sortBy(_.key)
assert(outputs.size === 2)
val out1 :: out2 :: Nil = outputs
assert(out1.key === "out-1")
assert(out1.valueType === DoubleObj)
assert(out2.key === "out-2")
assert(out2.valueType === DoubleObj)
}
}
}
示例6: withFixture
//设置package包名称以及导入依赖的类
trait FunSuitePlus extends org.scalatest.FunSuite
with com.typesafe.scalalogging.LazyLogging {
import org.scalatest.Outcome
override def withFixture(test: NoArgTest): Outcome = {
logger.info(s"Starting test case ${test.name}")
try {
test()
}
finally {
logger.info(s"Finished test case ${test.name}")
}
}
}
object TestImplicits {
import scalax.collection.GraphEdge.DiEdge
import scalax.collection.Graph
import rehearsal._
implicit class RichExprGraph(g: Graph[FSSyntax.Expr, DiEdge]) {
def fsGraph(): FSGraph = {
val alist = g.nodes.map(n => n.value -> FSGraph.key())
val m = alist.toMap
FSGraph(alist.map({ case (k,v) => (v, k) }).toMap,
Graph(m.values.toSeq: _*) ++
g.edges.toList.map(edge => DiEdge(m(edge._1.value), m(edge._2.value))))
}
}
}
示例7: newMySQLd
//设置package包名称以及导入依赖的类
package com.github.j5ik2o.scalatestplus.db
import org.scalatest.{ fixture, Outcome, TestData, TestSuiteMixin }
trait MySQLdOneInstancePerTest extends TestSuiteMixin with MySQLdSpecSupport { this: fixture.TestSuite =>
type FixtureParam = MySQLdContext
def newMySQLd(testData: TestData): MySQLdContext = {
startMySQLd(mySQLdConfig = MySQLdConfig(port = Some(RandomSocket.temporaryServerPort())))
}
override def withFixture(test: OneArgTest): Outcome = {
var _context: MySQLdContext = null
try {
_context = newMySQLd(test)
withFixture(test.toNoArgTest(_context))
} finally {
if (_context != null)
stopMySQLd(_context)
}
}
}
示例8: MySQLdContextWithFlywayContexts
//设置package包名称以及导入依赖的类
package com.github.j5ik2o.scalatestplus.db
import org.flywaydb.core.internal.util.jdbc.DriverDataSource
import org.scalatest.{ fixture, Outcome, TestData, TestSuiteMixin }
case class MySQLdContextWithFlywayContexts(mySQLdContext: MySQLdContext, flywayContexts: Seq[FlywayContext])
trait FlywayWithMySQLdOneInstancePerTest extends TestSuiteMixin with FlywaySpecSupport with MySQLdSpecSupport {
this: fixture.TestSuite =>
type FixtureParam = MySQLdContextWithFlywayContexts
def newMySQLd(testData: TestData): MySQLdContext = {
startMySQLd(mySQLdConfig = MySQLdConfig(port = Some(RandomSocket.temporaryServerPort())))
}
def classLoader: ClassLoader = getClass.getClassLoader
protected def classLoader(jdbcUrl: String): ClassLoader = getClass.getClassLoader
protected def driverClassName(jdbcUrl: String): String = MY_SQL_JDBC_DRIVER_NAME
protected def flywayConfig(jdbcUrl: String): FlywayConfig
protected def flywayMigrate(flywayContext: FlywayContext): Int =
flywayContext.flyway.migrate()
protected def flywayClean(flywayContext: FlywayContext): Unit =
flywayContext.flyway.clean()
override def withFixture(test: OneArgTest): Outcome = {
var mySQLdContext: MySQLdContext = null
var flywayContexts: Seq[FlywayContext] = null
try {
mySQLdContext = newMySQLd(test)
flywayContexts = mySQLdContext.jdbUrls.map { jdbcUrl =>
val flywayContext =
createFlywayContext(
FlywayConfigWithDataSource(new DriverDataSource(classLoader(jdbcUrl),
driverClassName(jdbcUrl),
jdbcUrl,
mySQLdContext.userName,
mySQLdContext.password),
flywayConfig(jdbcUrl))
)
flywayMigrate(flywayContext)
flywayContext
}
withFixture(test.toNoArgTest(MySQLdContextWithFlywayContexts(mySQLdContext, flywayContexts)))
} finally {
if (flywayContexts != null) {
flywayContexts.foreach(flywayClean)
}
if (mySQLdContext != null)
stopMySQLd(mySQLdContext)
}
}
}
示例9: StatusApiSpec
//设置package包名称以及导入依赖的类
package name.denyago.yasc.integration.httpapi
import name.denyago.yasc.Main
import org.scalatest.concurrent.Eventually
import org.scalatest.time.{Millis, Seconds, Span}
import org.scalatest.{Exceptional, FunSpec, Matchers, Outcome}
import scala.util.Try
import scalaj.http.Http
class StatusApiSpec extends FunSpec with Matchers with Eventually {
override def withFixture(test: NoArgTest): Outcome = {
val app = new Main(Array.empty[String])
app.run()
val outcome = Try { super.withFixture(test) }.recover {
case t: Throwable => Exceptional(t)
}.getOrElse(
Exceptional(new RuntimeException("No test outcome present"))
)
app.stop()
outcome
}
describe("Status HTTP API") {
implicit val patienceConfig =
PatienceConfig(timeout = scaled(Span(5, Seconds)), interval = scaled(Span(100, Millis)))
it("should return OK status when the server up and running") {
eventually {
val response = Http("http://localhost:8888/status").asString
response.code shouldEqual 200
response.body shouldEqual "{\"status\":\"OK\"}"
}
}
}
}
示例10: StateReaderEffectiveBalanceTest
//设置package包名称以及导入依赖的类
package com.wavesplatform.state2.reader
import java.util.concurrent.locks.ReentrantReadWriteLock
import com.wavesplatform.state2.StateStorage
import com.wavesplatform.state2.StateStorage._
import org.scalatest.{Matchers, Outcome, fixture}
import scorex.account.Address
class StateReaderEffectiveBalanceTest extends fixture.FunSuite with Matchers {
val acc: Address = Address.fromPublicKey(Array.emptyByteArray)
val stateHeight = 100
override type FixtureParam = StateStorage
override protected def withFixture(test: OneArgTest): Outcome = {
val storage = StateStorage(None, dropExisting = false).get
storage.setHeight(stateHeight)
test(storage)
}
test("exposes minimum of all 'current' and one 'previous' of oldest record") { storage =>
storage.balanceSnapshots.put(accountIndexKey(acc, 20), (0, 0, 1))
storage.balanceSnapshots.put(accountIndexKey(acc, 75), (20, 0, 200))
storage.balanceSnapshots.put(accountIndexKey(acc, 90), (75, 0, 100))
storage.lastBalanceSnapshotHeight.put(acc.bytes, 90)
new StateReaderImpl(storage, new ReentrantReadWriteLock()).effectiveBalanceAtHeightWithConfirmations(acc, stateHeight, 50) shouldBe 1
}
test("exposes current effective balance if no records in past N blocks are made") { storage =>
storage.balanceSnapshots.put(accountIndexKey(acc, 20), (0, 0, 1))
storage.portfolios.put(acc.bytes, (1, (0, 0), Map.empty))
storage.lastBalanceSnapshotHeight.put(acc.bytes, 20)
new StateReaderImpl(storage, new ReentrantReadWriteLock()).effectiveBalanceAtHeightWithConfirmations(acc, stateHeight, 50) shouldBe 1
}
test("doesn't include info older than N blocks") { storage =>
storage.balanceSnapshots.put(accountIndexKey(acc, 20), (0, 0, 1000))
storage.balanceSnapshots.put(accountIndexKey(acc, 50), (20, 0, 50000))
storage.balanceSnapshots.put(accountIndexKey(acc, 75), (50, 0, 100000))
storage.lastBalanceSnapshotHeight.put(acc.bytes, 75)
new StateReaderImpl(storage, new ReentrantReadWriteLock()).effectiveBalanceAtHeightWithConfirmations(acc, stateHeight, 50) shouldBe 50000
}
test("includes most recent update") { storage =>
storage.balanceSnapshots.put(accountIndexKey(acc, 20), (0, 0, 1000))
storage.balanceSnapshots.put(accountIndexKey(acc, 51), (20, 0, 50000))
storage.balanceSnapshots.put(accountIndexKey(acc, 100), (51, 0, 1))
storage.lastBalanceSnapshotHeight.put(acc.bytes, 100)
new StateReaderImpl(storage, new ReentrantReadWriteLock()).effectiveBalanceAtHeightWithConfirmations(acc, stateHeight, 50) shouldBe 1
}
}
示例11: SparkSpec
//设置package包名称以及导入依赖的类
package edu.fuberlin.hotspots
import org.apache.spark.{SparkConf, SparkContext}
import org.scalatest.{Outcome, Tag, fixture}
class SparkSpec extends fixture.FlatSpec {
case class FixtureParam(context:SparkContext)
override def withFixture(test:OneArgTest): Outcome ={
val conf = new SparkConf().setAppName("Test").setMaster("local[*]")
val sc = new SparkContext(conf)
try{withFixture(test.toNoArgTest(FixtureParam(sc)))}
finally{
if(sc != null && !sc.isStopped){
sc.stop()
}
}
}
}
object SparkSpec extends Tag("Spark")
示例12: 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
}
}
示例13: withFixture
//设置package包名称以及导入依赖的类
package jp.ne.opt.redshiftfake
import java.sql.{DriverManager, Connection}
import java.util.Properties
import jp.ne.opt.redshiftfake.util.Loan.using
import org.scalatest.{Outcome, fixture}
trait H2Sandbox { self: fixture.TestSuite =>
type FixtureParam = Connection
override def withFixture(test: OneArgTest): Outcome = {
val url = "jdbc:h2redshift:mem:redshift;MODE=PostgreSQL;DATABASE_TO_UPPER=false"
val prop = new Properties()
prop.setProperty("driver", "org.h2.jdbc.FakeH2Driver")
prop.setProperty("user", "sa")
Class.forName("org.h2.jdbc.FakeH2Driver")
using(DriverManager.getConnection(url, prop))(test)
}
}
示例14: PostgresDatabaseTest
//设置package包名称以及导入依赖的类
package caustic.postgres
import caustic.runtime.DatabaseTest
import com.mchange.v2.c3p0.ComboPooledDataSource
import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner
import org.scalatest.{BeforeAndAfterAll, Outcome}
@RunWith(classOf[JUnitRunner])
class PostgresDatabaseTest extends DatabaseTest with BeforeAndAfterAll {
var pool: ComboPooledDataSource = _
override def beforeAll(): Unit = {
this.pool = new ComboPooledDataSource()
this.pool.setDriverClass("org.postgresql.Driver")
this.pool.setJdbcUrl("jdbc:postgresql://localhost:5432/test?serverTimezone=UTC")
this.pool.setUser("postgres")
this.pool.setPassword("")
}
override def withFixture(test: OneArgTest): Outcome = {
// Delete all the table metadata.
val con = this.pool.getConnection()
val smt = con.createStatement()
smt.execute("DROP TABLE IF EXISTS schema")
con.close()
// Run the tests.
val database = PostgresDatabase(this.pool)
test(database)
}
override def afterAll(): Unit = {
this.pool.close()
}
}
示例15: MySQLDatabaseTest
//设置package包名称以及导入依赖的类
package caustic.mysql
import caustic.runtime.DatabaseTest
import com.mchange.v2.c3p0.ComboPooledDataSource
import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner
import org.scalatest.{BeforeAndAfterAll, Outcome}
@RunWith(classOf[JUnitRunner])
class MySQLDatabaseTest extends DatabaseTest with BeforeAndAfterAll {
var pool: ComboPooledDataSource = _
override def beforeAll(): Unit = {
this.pool = new ComboPooledDataSource()
this.pool.setDriverClass("com.mysql.cj.jdbc.Driver")
this.pool.setJdbcUrl(s"jdbc:mysql://localhost:3306/test?serverTimezone=UTC")
this.pool.setUser("root")
this.pool.setPassword("")
}
override def withFixture(test: OneArgTest): Outcome = {
// Delete all the table metadata.
val con = this.pool.getConnection()
val smt = con.createStatement()
smt.execute("DROP TABLE IF EXISTS `schema`")
con.close()
// Run the tests.
val database = MySQLDatabase(this.pool)
test(database)
}
override def afterAll(): Unit = {
this.pool.close()
}
}