• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Scala TestData类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: UsersSpec

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

import _root_.test._
import org.scalatest.Matchers._
import org.scalatest.{ TestData, WordSpec }
import org.scalatestplus.play.OneAppPerTest
import play.api._

class UsersSpec extends WordSpec with OneAppPerTest {

  override def newAppForTest(testData: TestData): Application = fakeApp

  "Users" should {
    "create and find" in {
      val users = app.injector.instanceOf(classOf[Users])
      val user = users.create(User(0L, "test1", true))
      user.id !== 0L
      val userFound = users.find(user.id)
      userFound shouldBe defined
      userFound.foreach(_.name shouldBe "test1")
    }


  }
} 
开发者ID:getquill,项目名称:play-quill-jdbc,代码行数:26,代码来源:UsersSpec.scala


示例2: ApplicationSpec

//设置package包名称以及导入依赖的类
import java.io.{File, PrintWriter}

import models.{UpdateRequest, V1thResult}
import org.scalatest.{BeforeAndAfter, TestData}
import org.scalatestplus.play._
import play.api.Application
import play.api.inject.guice.GuiceApplicationBuilder
import play.api.libs.json.Json
import play.api.test._
import play.api.test.Helpers._


class ApplicationSpec extends PlaySpec with OneAppPerTest with BeforeAndAfter {

  implicit override def newAppForTest(td: TestData): Application = {

    val f1File = new File("f1.csv")
    val content = "1, 2, 3, 4, 5"
    createTestFile(f1File, content)

    val f2File = new File("f2.csv")

    new GuiceApplicationBuilder().configure(
      Map(
        "f1.location" -> f1File.getAbsolutePath,
        "f2.location" -> f2File.getAbsolutePath
      )).build()
  }

  "NumberCalculationController" should {

    "return correct v1-th result" in {

      val v2=19
      val v3=2
      val v4=3
      val v1=v4

      await(route(app, FakeRequest(POST, "/postv2v3v4").withJsonBody(Json.toJson(UpdateRequest(v2,v3,v4)))).get)

      val result = route(app, FakeRequest(GET, s"/getf1v1?v1=${v1}")).get

      status(result) mustBe OK
      contentAsJson(result) must equal(Json.toJson(V1thResult(12)))
    }

  }

  def createTestFile(f2File: File, content: String): Unit = {
    val pw = new PrintWriter(f2File)
    pw.write(content)
    pw.close()
  }

} 
开发者ID:ydalekorey,项目名称:rest-calculator,代码行数:56,代码来源:ApplicationSpec.scala


示例3: ApiTest

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

import user.Fixtures

import scala.concurrent.Future
import play.api.libs.json.Json
import play.api.mvc.Result
import play.api.test.FakeApplication
import play.api.test.FakeRequest
import play.api.test.Helpers._
import org.scalatest.TestData

class ApiTest extends ApiSpecServer with TestUtils {

  implicit override def newAppForTest(td: TestData): FakeApplication = getFakeApp(new TestGlobal()(Fixtures))

  "The application " should {

    "return OK on ping" in {
      val result: Future[Result] = (new controllers.Application()).ping().apply(FakeRequest())
      val bodyText: String = contentAsString(result)
      bodyText mustBe "Ok"
    }
  }
} 
开发者ID:Driox,项目名称:play-app-seed,代码行数:26,代码来源:ApiTest.scala


示例4: ApplicationSpec

//设置package包名称以及导入依赖的类
import org.scalatest.TestData
import org.scalatestplus.play._
import play.api.inject.guice.GuiceApplicationBuilder
import play.api.test.Helpers._
import play.api.test._
import views.TodoView

class ApplicationSpec extends PlaySpec with OneAppPerTest {

  override def newAppForTest(td: TestData) = new GuiceApplicationBuilder()
    .configure(inMemoryDatabase(options = Map("MODE" -> "PostgreSQL")))
    .build()

  "Routes" should {

    "send 404 on a bad request" in {
      route(app, FakeRequest(GET, "/boum")).map(status) mustBe Some(NOT_FOUND)
    }
  }

  "TodoController" should {

    "return empty content" in {
      val home = route(app, FakeRequest(GET, "/todo")).get

      status(home) mustBe OK
      contentType(home) mustBe Some("application/json")
      contentAsJson(home).as[List[TodoView]] mustBe empty
    }
  }
} 
开发者ID:jrglee,项目名称:todo-play-scala-postgres,代码行数:32,代码来源:ApplicationSpec.scala


示例5: newAppForTest

//设置package包名称以及导入依赖的类
import org.scalatest.{Suite, TestData}
import org.scalatestplus.play.{OneAppPerSuite, OneAppPerTest, OneServerPerSuite, OneServerPerTest}
import play.api.{BuiltInComponents, _}

trait OneAppPerTestWithComponents[T <: BuiltInComponents]
  extends OneAppPerTest
    with WithApplicationComponents[T] {
  this: Suite =>

  override def newAppForTest(testData: TestData): Application = newApplication
}

trait OneAppPerSuiteWithComponents[T <: BuiltInComponents]
  extends OneAppPerSuite
    with WithApplicationComponents[T] {
  this: Suite =>
  override implicit lazy val app: Application = newApplication
}

trait OneServerPerTestWithComponents[T <: BuiltInComponents]
  extends OneServerPerTest
    with WithApplicationComponents[T] {
  this: Suite =>

  override def newAppForTest(testData: TestData): Application = newApplication
}

trait OneServerPerSuiteWithComponents[T <: BuiltInComponents]
  extends OneServerPerSuite
    with WithApplicationComponents[T] {
  this: Suite =>

  override implicit lazy val app: Application = newApplication
} 
开发者ID:wsargent,项目名称:play-cucumber,代码行数:35,代码来源:ScalaTestWithComponents.scala


示例6: 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


示例7: 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


示例8: HomeControllerSpec

//设置package包名称以及导入依赖的类
import org.scalatest.TestData
import org.scalatestplus.play._
import play.api.Application
import play.api.inject.guice.GuiceApplicationBuilder
import play.api.test._
import play.api.test.Helpers._

class HomeControllerSpec extends PlaySpec with OneAppPerTest {

  val config = Map(
    "monzo.clientId" -> "testClientId",
    "monzo.clientSecret" -> "testClientSecret",
    "monzo.redirectUri" -> "http://redirectmehere.com"
  )

  implicit override def newAppForTest(testData: TestData): Application =
    new GuiceApplicationBuilder().configure(config).build()

  "AuthController" should {

    "not return NOT_FOUND" when {

      "the index page is accessed" in {
        route(app, FakeRequest(GET, "/")).map(status) mustBe Some(OK)
      }

    }

    "render the index page" in {
      val home = route(app, FakeRequest(GET, "/")).get

      status(home) mustBe OK
      contentType(home) mustBe Some("text/html")
      contentAsString(home) must include ("Authorise")
    }

    "redirect to monzo for auth" in {
      val oauth = route(app, FakeRequest(GET, "/oauth/monzo")).get

      status(oauth) mustBe SEE_OTHER
      redirectLocation(oauth).get must include(
        "https://auth.getmondo.co.uk/?client_id=testClientId&redirect_uri=http://redirectmehere.com/oauth/callback&response_type=code&state="
      )
    }

  }


} 
开发者ID:adamtrousdale,项目名称:monzo-roundup,代码行数:50,代码来源:HomeControllerSpec.scala


示例9: AppConfigurationSampleSpec

//设置package包名称以及导入依赖的类
package uk.gov.hmrc.exampleplay25microservice.controllers

import org.scalatest.TestData
import org.scalatestplus.play.{OneAppPerTest, PlaySpec}
import play.api.{Application, Play}
import play.api.inject.guice.GuiceApplicationBuilder

class AppConfigurationSampleSpec extends PlaySpec with OneAppPerTest {

  override def newAppForTest(testData: TestData): Application = {
    val builder = new GuiceApplicationBuilder()
    testData.name match {
      case a if a.matches("^.*one$") => builder.configure("foo" -> "one").build()
      case b if b.matches("^.*two$") => builder.configure("foo" -> "two").build()
      case c if c.matches("^.*three$") => builder.configure("foo" -> "three").build()
      case _ => builder.configure("foo" -> "default").build()
    }
  }

  "configuration of individual case" should {

    "one" in {
      Play.current.configuration.getString("foo") must be (Some("one"))
    }

    "two" in {
      Play.current.configuration.getString("foo") must be (Some("two"))
    }

    "three" in {
      Play.current.configuration.getString("foo") must be (Some("three"))
    }

  }

} 
开发者ID:hmrc,项目名称:example-play-25-microservice,代码行数:37,代码来源:AppConfigurationSampleSpec.scala


示例10: ApplicationSpec

//设置package包名称以及导入依赖的类
import org.scalatest.TestData
import org.scalatestplus.play._
import play.api.inject.guice.GuiceApplicationBuilder
import play.api.test.Helpers._
import play.api.test._
import views.TodoView

class ApplicationSpec extends PlaySpec with OneAppPerTest {

  override def newAppForTest(td: TestData) = new GuiceApplicationBuilder()
    .configure(inMemoryDatabase(options = Map("MODE" -> "PostgreSQL")))
    .build()

  "Routes" should {

    "send 404 on a bad request" in {
      route(app, FakeRequest(GET, "/boum")).map(status) mustBe Some(NOT_FOUND)
    }
  }

  "TodoController" should {

    "return empty content" in {
      val home = route(app, FakeRequest(GET, "/todos")).get

      status(home) mustBe OK
      contentType(home) mustBe Some("application/json")
      contentAsJson(home).as[List[TodoView]] mustBe empty
    }
  }
} 
开发者ID:jkuoctanner,项目名称:todobackend-play,代码行数:32,代码来源:ApplicationSpec.scala


示例11: newAppForTest

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

import com.google.inject.AbstractModule
import com.mohiva.play.silhouette.api.Environment
import com.mohiva.play.silhouette.test.FakeEnvironment
import com.typesafe.config.ConfigFactory
import models.User
import net.codingwell.scalaguice.ScalaModule
import org.scalatest.{BeforeAndAfterEach, Suite, TestData}
import org.scalatestplus.play.{OneAppPerTest, PlaySpec}
import play.api.db.DBApi
import play.api.db.evolutions.Evolutions
import play.api.{Application, Configuration, Mode}
import play.api.inject.Injector
import play.api.inject.guice.GuiceApplicationBuilder
import utils.auth.DefaultEnv

import scala.concurrent.ExecutionContext.Implicits.global
import scala.reflect.ClassTag

trait PlogSpec extends PlaySpec with OneAppPerTest with BeforeAndAfterEach { this: Suite =>

  lazy val appBuilder: GuiceApplicationBuilder = new GuiceApplicationBuilder()
    .overrides(new FakeModule)
    .in(Mode.Test)
    .overrides(new FakeModule)
    .loadConfig(Configuration(ConfigFactory.load("application.test.conf")))

  lazy val injector: Injector = appBuilder.injector()
  lazy val databaseApi: DBApi = injector.instanceOf[DBApi]

  override def newAppForTest(testData: TestData): Application = {
    appBuilder
      .build()
  }

  override def beforeEach {
    val dbApi = databaseApi
    Evolutions.applyEvolutions(dbApi.database("default"))
  }

  override def afterEach {
    Evolutions.cleanupEvolutions(databaseApi.database("default"))
  }

  
  implicit val env: Environment[DefaultEnv] = new FakeEnvironment[DefaultEnv](
    Seq(
      barUser.loginInfo -> barUser,
      fooUser.loginInfo -> fooUser
    )
  )

  class FakeModule extends AbstractModule with ScalaModule {
    def configure() = {
      bind[Environment[DefaultEnv]].toInstance(env)
    }
  }
} 
开发者ID:edgarmueller,项目名称:plog-backend,代码行数:60,代码来源:PlogSpec.scala


示例12: IntegrationSpec

//设置package包名称以及导入依赖的类
import com.typesafe.config.ConfigFactory
import org.scalatest.{BeforeAndAfter, TestData}
import org.scalatestplus.play._
import play.api.{Application, Configuration}
import play.api.inject.guice.GuiceApplicationBuilder
import play.api.test._
import play.api.test.Helpers._


class IntegrationSpec extends PlaySpec with OneServerPerTest with BeforeAndAfter with WithTestDatabase with OneBrowserPerTest with HtmlUnitFactory {

  // Override newAppForTest if you need a FakeApplication with other than non-default parameters
  implicit override def newAppForTest(testData: TestData): Application =
      GuiceApplicationBuilder().loadConfig(new Configuration(ConfigFactory.load("application.test.conf"))).build(

      )

  "Application" should {

    "work from within a browser" in {

      go to ("http://localhost:" + port)

      // contentAsJson(home) mustEqual Json.parse("""{"status": "Ok", "message": "application is ready"}""")
      pageSource must include ("application is ready")
    }
  }
} 
开发者ID:ZGIS,项目名称:smart-portal-backend,代码行数:29,代码来源:IntegrationSpec.scala


示例13: ParsedResultsRepositoryMock

//设置package包名称以及导入依赖的类
import org.scalatest.TestData
import play.api.db.evolutions.EvolutionsModule
import play.api.db.slick.SlickModule
import play.api.inject._
import play.api.inject.guice.GuiceApplicationBuilder
import play.api.{Application, Mode}
import repo.{SavedParseResult, ParsedResultsRepository}
import play.api.libs.concurrent.Execution.Implicits.defaultContext

import scala.concurrent.Future

class ParsedResultsRepositoryMock extends ParsedResultsRepository {
  override def load(id: String): Future[Option[SavedParseResult]] = id match {
    case "abcdef" => Future { Some(SavedParseResult("grammar test; id: ID+;", "lexer grammar test; ID: 'id'+;", "id", "id", "abcdef", Some(1))) }
    case _ => Future { None }
  } 
  override def save(parsedResult: SavedParseResult): Future[String] = Future { "abcdef" }

  override def codeUnique(code: String): Future[Boolean] = Future.successful(true)
}

trait AntlrFakeApp {
  def antlrFakeApp(testData: TestData): Application = {
    new GuiceApplicationBuilder()
      .in(Mode.Test)
      .disable[SlickModule]
      .disable[EvolutionsModule]
      .disable[play.api.db.slick.evolutions.EvolutionsModule]
      .overrides(bind[ParsedResultsRepository].to[ParsedResultsRepositoryMock])
      .build
  }
} 
开发者ID:alek-sys,项目名称:antlrpad,代码行数:33,代码来源:AntlrFakeApp.scala


示例14: newAppForTest

//设置package包名称以及导入依赖的类
import org.scalatest.{Suite, TestData}
import org.scalatestplus.play._
import play.api.{BuiltInComponents, _}

trait OneAppPerTestWithComponents[T <: BuiltInComponents]
  extends OneAppPerTest
    with WithApplicationComponents[T] {
  this: Suite =>

  override def newAppForTest(testData: TestData): Application = newApplication
}

trait OneAppPerSuiteWithComponents[T <: BuiltInComponents]
  extends OneAppPerSuite
    with WithApplicationComponents[T] {
  this: Suite =>
  override implicit lazy val app: Application = newApplication
}

trait OneServerPerTestWithComponents[T <: BuiltInComponents]
  extends OneServerPerTest
    with WithApplicationComponents[T] {
  this: Suite =>

  override def newAppForTest(testData: TestData): Application = newApplication
}

trait OneServerPerSuiteWithComponents[T <: BuiltInComponents]
  extends OneServerPerSuite
    with WithApplicationComponents[T] {
  this: Suite =>

  override implicit lazy val app: Application = newApplication
} 
开发者ID:wsargent,项目名称:slim-play-with-custom-logger,代码行数:35,代码来源:ScalaTestWithComponents.scala



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Scala Controller类代码示例发布时间:2022-05-23
下一篇:
Scala ServiceLocator类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap