当前位置: 首页>>代码示例>>Scala>>正文


Scala fixture类代码示例

本文整理汇总了Scala中org.scalatest.fixture的典型用法代码示例。如果您正苦于以下问题:Scala fixture类的具体用法?Scala fixture怎么用?Scala fixture使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了fixture类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。

示例1: DefaultSerializersSpec

//设置package包名称以及导入依赖的类
package com.commodityvectors.snapshotmatchers

import org.scalatest.{Matchers, fixture}

class DefaultSerializersSpec extends fixture.WordSpec with Matchers with SnapshotMatcher {
  case class Test(value: Integer)

  "DefaultSerializers" should {
    "Serialize simple case classes" in { implicit test =>
      SnapshotSerializer.serialize(Test(1)) shouldEqual "Test(1)"
    }

    "Serialize option" in { implicit test =>
      val element: Option[Test] = None
      SnapshotSerializer.serialize(Option(Test(1))) shouldEqual "Some(Test(1))"
      SnapshotSerializer.serialize(element) shouldEqual "None"
    }

    "Serializer array" in { implicit test =>
      SnapshotSerializer.serialize(List(Test(1))) shouldEqual "List(Test(1))"
      SnapshotSerializer.serialize(Seq(Test(1))) shouldEqual "List(Test(1))"
      SnapshotSerializer.serialize(Vector(Test(1))) shouldEqual "Vector(Test(1))"
    }

     "Serializer maps" in { implicit test =>
       SnapshotSerializer.serialize(Map(Test(1) -> Test(2))) shouldEqual "Map(Test(1) -> Test(2))"
       SnapshotSerializer.serialize(Map("key" -> Test(2))) shouldEqual "Map(key -> Test(2))"
       SnapshotSerializer.serialize(Map(10 -> Test(2))) shouldEqual "Map(10 -> Test(2))"
       SnapshotSerializer.serialize(Map(10.0 -> Test(2))) shouldEqual "Map(10.0 -> Test(2))"
     }

    "Serialize composed types" in { implicit test =>
      case class Complex(v1: Int, v2: String, v3: Double, v4: List[Option[String]], v5: Map[Option[String], Seq[Complex]])
      val child = Complex(1, "2", 3.0, List(Option("Me")), Map())
      val instance = Complex(1, "2", 3.0, List(Option("Me")), Map(Option("you") -> Seq(child)))
      SnapshotSerializer.serialize(instance) shouldEqual
        s"""|Complex(
            |  v1 = 1,
            |  v2 = "2",
            |  v3 = 3.0,
            |  v4 = List(Some(Me)),
            |  v5 = Map(Some(you) -> List(Complex(1,2,3.0,List(Some(Me)),Map())))
            |)""".stripMargin
    }

    "Allow custom serializers" in { implicit test =>
      implicit lazy val customSerializer = new SnapshotSerializer[Test] {
        override def serialize(in: Test): String = s"CustomSerializer: ${in.value}"
      }

      SnapshotSerializer.serialize(Test(1)) shouldEqual "CustomSerializer: 1"
    }
  }
} 
开发者ID:commodityvectors,项目名称:scalatest-snapshot-matchers,代码行数:55,代码来源:DefaultSerializersSpec.scala

示例2: SnapshotGenerationSpec

//设置package包名称以及导入依赖的类
package com.commodityvectors.snapshotmatchers

import java.io.File

import org.apache.commons.io.FileUtils
import org.scalatest.{BeforeAndAfterEach, Matchers, fixture}

import scala.util.Try

class SnapshotGenerationSpec extends fixture.WordSpec with Matchers with SnapshotMatcher with BeforeAndAfterEach {

  val snapshotFolder: String = "scalatest-snapshot-matcher-core/src/test/__snapshots__"
  val currentSpecPath: String = s"$snapshotFolder/com/commodityvectors/snapshotmatchers/SnapshotGenerationSpec"

  override def afterEach(): Unit = {
    Try(FileUtils.deleteDirectory(new File(snapshotFolder)))
  }

  "SnapshotMatcher" should {
    "generate snapshot file with expectation" in { implicit test =>
      val value: Int = 1
      value should matchSnapshot[Int]()
      FileUtils.readFileToString(
        new File(s"$currentSpecPath/snapshotmatcher-should-generate-snapshot-file-with-expectation.snap")
      ) shouldEqual "1"
    }

    "generate file with custom id" in { implicit test =>
      val value = 10
      value should matchSnapshot[Int]("customId")
      FileUtils.readFileToString(
        new File(s"$currentSpecPath/customId.snap")
      ) shouldEqual "10"
    }
  }
} 
开发者ID:commodityvectors,项目名称:scalatest-snapshot-matchers,代码行数:37,代码来源:SnapshotGenerationSpec.scala

示例3: PlayJsonSnapshotMatcherSpec

//设置package包名称以及导入依赖的类
package com.commodityvectors.snapshotmatchers.playJson

import java.io.File

import com.commodityvectors.snapshotmatchers.{SnapshotMatcher, SnapshotSerializer}
import org.apache.commons.io.FileUtils
import org.scalatest.{BeforeAndAfterEach, Matchers, fixture}
import play.api.libs.json.{Format, JsValue, Json}

import scala.util.Try

class PlayJsonSnapshotMatcherSpec extends fixture.WordSpec with Matchers with SnapshotMatcher with PlayJsonSnapshotMatcher with BeforeAndAfterEach {
  case class Test(value: Int)
  implicit lazy val jsonFormat: Format[Test] = Json.format[Test]

  val snapshotFolder: String = "scalatest-snapshot-matcher-play-json/src/test/__snapshots__"
  val currentSpecPath: String = s"$snapshotFolder/com/commodityvectors/snapshotmatchers/playJson/PlayJsonSnapshotMatcherSpec"

  override def afterEach(): Unit = {
    Try(FileUtils.deleteDirectory(new File(snapshotFolder)))
  }

  "PlayJsonSnapshotMatcherSpec" should {
    "pretty print json" in { implicit test =>
      val instance = Test(1)
      SnapshotSerializer.serialize(Json.toJson(instance)) shouldEqual
        s"""{
           |  "value" : 1
           |}""".stripMargin
    }

    "generate json snapshot file" in { implicit test =>
      val instance = Test(1)
      Json.toJson(instance) should matchSnapshot[JsValue]("customId")
      FileUtils.readFileToString(
        new File(s"$currentSpecPath/customId.snap")
      ) shouldEqual
        s"""{
           |  "value" : 1
           |}""".stripMargin
    }

    "allow deserialization" in { implicit test =>
      val instance = Test(1)
      Json.toJson(instance) should matchSnapshot[JsValue]("anotherId")
      "anotherId" should deserializeAs(instance)
    }
  }
} 
开发者ID:commodityvectors,项目名称:scalatest-snapshot-matchers,代码行数:50,代码来源:PlayJsonSnapshotMatcherSpec.scala

示例4: ParserTest

//设置package包名称以及导入依赖的类
package org.sparkline.spark.udfs.contains

import org.scalatest.{BeforeAndAfterAll, fixture}

class ParserTest extends fixture.FunSuite with
  fixture.TestDataFixture with BeforeAndAfterAll {

  test("1") { td =>
    val p = new CExpressionParser(Map("slice" -> 2))

    var l = new p.lexical.Scanner("slice(1)")
    while(!l.atEnd) {
      println(l.first)
      l = l.rest
    }
  }

  test("2") { td =>
    val p = new CExpressionParser(Map("slice" -> 2))

    println(p("slice(1)"))
  }

  test("queries") { td =>
    val p = new CExpressionParser(Map("slice" -> 2))

    val queries = Seq(
      "slice(1) and slice(2)",
      "slice(1) or slice(2)",
      "not slice(1) and slice(2)",
      "slice = 1 and not slice(2)",
      "slice in (1,2) or not slice(3)"
    )

    for(s <- queries)
      println(p(s))
  }

} 
开发者ID:SparklineData,项目名称:spark-functions,代码行数:40,代码来源:ParserTest.scala

示例5: beforeAll

//设置package包名称以及导入依赖的类
package tests

import org.flywaydb.core.Flyway
import org.scalatest.{BeforeAndAfterAll, fixture}
import scalikejdbc.config.DBsWithEnv
import scalikejdbc.scalatest.AutoRollback
import scalikejdbc.{ConnectionPool, GlobalSettings}
import tests.support.MockitoSupport

trait FixtureTestSuite extends fixture.FunSuiteLike with AutoRollback with MockitoSupport with BeforeAndAfterAll {

  override def beforeAll(): Unit = {
    super.beforeAll()
    GlobalSettings.jtaDataSourceCompatible = true
    DBsWithEnv("test").setupAll()

    val flyway = new Flyway()
    flyway.setDataSource(ConnectionPool().dataSource)
    flyway.clean()
    flyway.migrate()
  }

  override def afterAll(): Unit = {
    super.afterAll()
    DBsWithEnv("test").closeAll()
  }
} 
开发者ID:lymr,项目名称:fun-chat,代码行数:28,代码来源:FixtureTestSuite.scala

示例6: 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)
    }
  }
} 
开发者ID:Sciss,项目名称:FScape-next,代码行数:57,代码来源:SerializationSpec.scala

示例7: MixedPlaySpecWithNoDefaultApp

//设置package包名称以及导入依赖的类
import org.scalatest.concurrent.{Eventually, IntegrationPatience}
import org.scalatest.{MustMatchers, OptionValues, fixture}
import org.scalatestplus.play.{PortNumber, WsScalaTestClient}
import play.api.libs.ws.{WSClient, WSRequest}
import play.api.mvc.Call

abstract class MixedPlaySpecWithNoDefaultApp extends fixture.WordSpec
  with MustMatchers
  with OptionValues
  with MixedFixturesWithNoDefaultApp
  with Eventually
  with IntegrationPatience
  with WsScalaTestClient
{

  //def wsCall(call: Call)(implicit portNumber: PortNumber, wsClient: WSClient): WSRequest = doCall(call.url, wsClient, portNumber)

  // def wsUrl(url: String)(implicit portNumber: PortNumber, wsClient: WSClient): WSRequest = doCall(url, wsClient, portNumber)

  //private def doCall(url: String, wsClient: WSClient, portNumber: PortNumber) = {
  //  wsClient.url("http://localhost:" + portNumber.value + url)
  //}
} 
开发者ID:wsargent,项目名称:play-cucumber,代码行数:24,代码来源:MixedPlaySpecWithNoDefaultApp.scala

示例8: 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)
    }
  }

} 
开发者ID:j5ik2o,项目名称:scalatestplus-db,代码行数:25,代码来源:MySQLdOneInstancePerTest.scala

示例9: WithMySQLdContext

//设置package包名称以及导入依赖的类
package com.github.j5ik2o.scalatestplus.db

import org.scalatest.{ fixture, TestSuiteMixin }

trait MySQLdMixedFixtures extends TestSuiteMixin with fixture.UnitFixture with MySQLdSpecSupport {
  this: fixture.TestSuite =>

  abstract class WithMySQLdContext(
      startMySQLdF: => MySQLdContext =
        startMySQLd(this.mySQLdConfig.copy(port = Some(RandomSocket.temporaryServerPort())),
                    this.downloadConfig,
                    this.schemaConfigs),
      stopMySQLdF: (MySQLdContext) => Unit = stopMySQLd
  ) extends fixture.NoArg {

    private var _context: MySQLdContext = _

    protected def mySQLdContext: MySQLdContext = _context

    override def apply(): FixtureParam = {
      def callSuper(): FixtureParam = super.apply()
      try {
        _context = startMySQLdF
        callSuper()
      } finally {
        if (_context != null)
          stopMySQLdF(_context)
      }
    }
  }

} 
开发者ID:j5ik2o,项目名称:scalatestplus-db,代码行数:33,代码来源:MySQLdMixedFixtures.scala

示例10: 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)
    }
  }

} 
开发者ID:j5ik2o,项目名称:scalatestplus-db,代码行数:60,代码来源:FlywayWithMySQLdOneInstancePerTest.scala

示例11: FlywayWithMySQLdMixedFreeSpec

//设置package包名称以及导入依赖的类
package com.github.j5ik2o.scalatestplus.db

import com.wix.mysql.EmbeddedMysql
import org.scalatest.{ fixture, MustMatchers }

class FlywayWithMySQLdMixedFreeSpec extends fixture.FreeSpec with MustMatchers with FlywayWithMySQLdMixedFixtures {

  override protected val schemaConfigs: Seq[SchemaConfig] = Seq(SchemaConfig("test"))

  var mysqld: EmbeddedMysql = _

  "FlywayMixedFreeSpec" - {
    "should start & stop mysql1" in new WithFlywayContext(_ => FlywayConfig(Seq("db"))) {
      println(s"context = $mySQLdContext")
      mySQLdContext mustNot be(null)
      mySQLdContext.schemaConfigs.head.name mustBe "test"
      mysqld = mySQLdContext.embeddedMysql

    }
    "should start & stop mysql2" in new WithFlywayContext(_ => FlywayConfig(Seq("db"))) {
      println(s"context = $mySQLdContext")
      mySQLdContext mustNot be(null)
      mySQLdContext.schemaConfigs.head.name mustBe "test"
      mySQLdContext.embeddedMysql mustNot be(mysqld)
    }
  }
} 
开发者ID:j5ik2o,项目名称:scalatestplus-db,代码行数:28,代码来源:FlywayWithMySQLdMixedFreeSpec.scala

示例12: MySQLdMixedFreeSpec

//设置package包名称以及导入依赖的类
package com.github.j5ik2o.scalatestplus.db

import com.wix.mysql.EmbeddedMysql
import org.scalatest.{ fixture, MustMatchers }

class MySQLdMixedFreeSpec extends fixture.FreeSpec with MustMatchers with MySQLdMixedFixtures {

  override protected val schemaConfigs: Seq[SchemaConfig] = Seq(SchemaConfig("test"))

  var mysqld: EmbeddedMysql = _

  "WixMySQLMixedFreeSpec" - {
    "should start & stop mysql1" in new WithMySQLdContext() {
      println(s"context = $mySQLdContext")
      mySQLdContext mustNot be(null)
      mySQLdContext.schemaConfigs.head.name mustBe "test"
      mysqld = mySQLdContext.embeddedMysql
    }
    "should start & stop mysql2" in new WithMySQLdContext() {
      println(s"context = $mySQLdContext")
      mySQLdContext mustNot be(null)
      mySQLdContext.schemaConfigs.head.name mustBe "test"
      mySQLdContext.embeddedMysql mustNot be(mysqld)
    }
  }
} 
开发者ID:j5ik2o,项目名称:scalatestplus-db,代码行数:27,代码来源:MySQLdMixedFreeSpec.scala

示例13: MySQLdOnInstancePerTestOfFreeSpec

//设置package包名称以及导入依赖的类
package com.github.j5ik2o.scalatestplus.db

import com.wix.mysql.EmbeddedMysql
import org.scalatest.{ fixture, MustMatchers }

class MySQLdOnInstancePerTestOfFreeSpec extends fixture.FreeSpec with MustMatchers with MySQLdOneInstancePerTest {

  override protected val schemaConfigs: Seq[SchemaConfig] = Seq(SchemaConfig("test"))

  var mysqld: EmbeddedMysql = _

  "WixMySQLOnInstancePerTestOfFreeSpec" - {
    "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)
    }
  }
} 
开发者ID:j5ik2o,项目名称:scalatestplus-db,代码行数:27,代码来源:MySQLdOnInstancePerTestOfFreeSpec.scala

示例14: FlywayWithMySQLdMixedFunSpec

//设置package包名称以及导入依赖的类
package com.github.j5ik2o.scalatestplus.db

import com.wix.mysql.EmbeddedMysql
import org.scalatest.{ fixture, MustMatchers }

class FlywayWithMySQLdMixedFunSpec extends fixture.FunSpec with MustMatchers with FlywayWithMySQLdMixedFixtures {

  override protected val schemaConfigs: Seq[SchemaConfig] = Seq(SchemaConfig("test"))

  var mysqld: EmbeddedMysql = _

  describe("FlywayMixedFunSpec") {
    it("should start & stop mysql1") {
      new WithFlywayContext(_ => FlywayConfig(Seq("db"))) {
        println(s"context = $mySQLdContext")
        mySQLdContext mustNot be(null)
        mySQLdContext.schemaConfigs.head.name mustBe "test"
        mysqld = mySQLdContext.embeddedMysql

      }
    }
    it("should start & stop mysql2") {
      new WithFlywayContext(_ => FlywayConfig(Seq("db"))) {
        println(s"context = $mySQLdContext")
        mySQLdContext mustNot be(null)
        mySQLdContext.schemaConfigs.head.name mustBe "test"
        mySQLdContext.embeddedMysql mustNot be(mysqld)
      }
    }
  }
} 
开发者ID:j5ik2o,项目名称:scalatestplus-db,代码行数:32,代码来源:FlywayWithMySQLdMixedFunSpec.scala

示例15: MySQLdMixedFunSpec

//设置package包名称以及导入依赖的类
package com.github.j5ik2o.scalatestplus.db

import com.wix.mysql.EmbeddedMysql
import org.scalatest.{ fixture, MustMatchers }

class MySQLdMixedFunSpec extends fixture.FunSpec with MustMatchers with MySQLdMixedFixtures {

  override protected val schemaConfigs: Seq[SchemaConfig] = Seq(SchemaConfig("test"))

  var mysqld: EmbeddedMysql = _

  describe("WixMySQLMixedFunSpec") {
    it("should start & stop mysql1") {
      new WithMySQLdContext() {
        println(s"context = $mySQLdContext")
        mySQLdContext mustNot be(null)
        mySQLdContext.schemaConfigs.head.name mustBe "test"
        mysqld = mySQLdContext.embeddedMysql
      }
    }
    it("should start & stop mysql2") {
      new WithMySQLdContext() {
        println(s"context = $mySQLdContext")
        mySQLdContext mustNot be(null)
        mySQLdContext.schemaConfigs.head.name mustBe "test"
        mySQLdContext.embeddedMysql mustNot be(mysqld)
      }
    }
  }
} 
开发者ID:j5ik2o,项目名称:scalatestplus-db,代码行数:31,代码来源:MySQLdMixedFunSpec.scala


注:本文中的org.scalatest.fixture类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。