org.scalatest.TestSuite Scala Examples
The following examples show how to use org.scalatest.TestSuite.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
Example 1
Source File: SparkSessionSpec.scala From spark-alchemy with Apache License 2.0 | 5 votes |
package com.swoop.test_utils import org.apache.logging.log4j.Level import org.apache.spark.sql.SQLContext import org.apache.spark.sql.test.{SharedSparkSessionBase, TestSparkSession} import org.apache.spark.{SparkConf, SparkContext} import org.scalatest.TestSuite import scala.util.Try trait SparkSessionSpec extends SharedSparkSessionBase { this: TestSuite => override protected def createSparkSession: TestSparkSession = { val spark = super.createSparkSession configureLoggers(sparkLogLevel) spark } def sparkSession = spark def sqlc: SQLContext = sparkSession.sqlContext def sc: SparkContext = sparkSession.sparkContext protected def sparkLogLevel = Try(sys.env("SPARK_LOG_LEVEL")).getOrElse("WARN").toUpperCase match { case "DEBUG" => Level.DEBUG case "INFO" => Level.INFO case "WARN" => Level.WARN case _ => Level.ERROR } protected def configureLoggers(): Unit = configureLoggers(sparkLogLevel) protected def configureLoggers(logLevel: Level): Unit = { // Set logging through log4j v1 APIs also as v2 APIs are too tricky to manage org.apache.log4j.Logger.getRootLogger.setLevel(logLevel match { case Level.DEBUG => org.apache.log4j.Level.DEBUG case Level.INFO => org.apache.log4j.Level.INFO case Level.WARN => org.apache.log4j.Level.WARN case Level.ERROR => org.apache.log4j.Level.ERROR }) } override protected def sparkConf: SparkConf = super.sparkConf .set("spark.driver.bindAddress", "127.0.0.1") }
Example 2
Source File: StandaloneSanityTestSupport.scala From openwhisk with Apache License 2.0 | 5 votes |
package org.apache.openwhisk.standalone import org.scalatest.{Canceled, Outcome, TestSuite} trait StandaloneSanityTestSupport extends TestSuite { protected def supportedTests: Set[String] override def withFixture(test: NoArgTest): Outcome = { if (supportedTests.contains(test.name)) { super.withFixture(test) } else { Canceled() } } }
Example 3
Source File: KubeClientSupport.scala From openwhisk with Apache License 2.0 | 5 votes |
package org.apache.openwhisk.core.containerpool.kubernetes.test import common.StreamLogging import io.fabric8.kubernetes.client.server.mock.KubernetesMockServer import io.fabric8.kubernetes.client.utils.HttpClientUtils.createHttpClientForMockServer import io.fabric8.kubernetes.client.{ConfigBuilder, DefaultKubernetesClient} import okhttp3.TlsVersion.TLS_1_0 import org.scalatest.{BeforeAndAfterAll, Suite, TestSuite} import scala.concurrent.duration._ trait KubeClientSupport extends TestSuite with BeforeAndAfterAll with StreamLogging { self: Suite => protected def useMockServer = true val server = new KubernetesMockServer(false) protected lazy val (kubeClient, closeable) = { if (useMockServer) { server.init() def defaultClient = { val config = new ConfigBuilder() .withMasterUrl(server.url("/")) .withTrustCerts(true) .withTlsVersions(TLS_1_0) .withNamespace("test") .build new DefaultKubernetesClient(createHttpClientForMockServer(config), config) } (defaultClient, () => server.destroy()) } else { val client = new DefaultKubernetesClient( new ConfigBuilder() .withConnectionTimeout(1.minute.toMillis.toInt) .withRequestTimeout(1.minute.toMillis.toInt) .build()) (client, () => client.close()) } } override def beforeAll(): Unit = { if (!useMockServer) { val kubeconfig = sys.env.get("KUBECONFIG") assume(kubeconfig.isDefined, "KUBECONFIG env must be defined") println(s"Using kubeconfig from ${kubeconfig.get}") } super.beforeAll() } override def afterAll(): Unit = { super.afterAll() closeable.apply() } }
Example 4
Source File: ScalaTestWithComponents.scala From slim-play with MIT License | 5 votes |
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) val initialSettings = Map.empty[String, AnyRef] ApplicationLoader.Context.create(env, initialSettings) } }
Example 5
Source File: MyCompileTimeSpecs.scala From slim-play with MIT License | 5 votes |
import helpers.{ OneAppPerSuiteWithComponents, OneAppPerTestWithComponents, OneServerPerSuiteWithComponents, OneServerPerTestWithComponents } import org.scalatest.TestSuite import play.api.ApplicationLoader.Context import play.api.libs.ws.ahc.AhcWSComponents 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) }
Example 6
Source File: ScreenCapturingSpec.scala From renku with Apache License 2.0 | 5 votes |
package ch.renku.acceptancetests.tooling import java.io.File import java.nio.file.Paths import java.time.LocalDateTime.now import java.time.format.DateTimeFormatter.ofPattern import org.scalatest.{Outcome, TestSuite} import org.scalatestplus.selenium.{Driver, WebBrowser} trait ScreenCapturingSpec extends ScreenCapturing { this: AcceptanceSpec => override def withFixture(test: NoArgTest): Outcome = { val outcome = test() if (outcome.isExceptional) { saveScreenshot } outcome } }
Example 7
Source File: FlywayWithMySQLSpecSupport.scala From scala-ddd-base with MIT License | 5 votes |
package com.github.j5ik2o.dddbase.example.repository.util import java.io.File import com.github.j5ik2o.scalatestplus.db._ import com.wix.mysql.distribution.Version._ import org.scalatest.TestSuite import scala.concurrent.duration._ trait FlywayWithMySQLSpecSupport extends FlywayWithMySQLdOneInstancePerSuite with RandomPortSupport { this: TestSuite => override protected lazy val mySQLdConfig: MySQLdConfig = MySQLdConfig( version = v5_6_21, port = Some(temporaryServerPort()), userWithPassword = Some(UserWithPassword("dddbase", "dddbase")), timeout = Some((30 seconds) * sys.env.getOrElse("SBT_TEST_TIME_FACTOR", "1").toDouble) ) 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 = "dddbase")) override protected def flywayConfig(jdbcUrl: String): FlywayConfig = FlywayConfig( locations = Seq( "filesystem:flyway/src/test/resources/rdb-migration" ), placeholderConfig = Some( PlaceholderConfig( placeholderReplacement = true, placeholders = Map("engineName" -> "MEMORY", "idSequenceNumberEngineName" -> "MyISAM") ) ) ) }
Example 8
Source File: TestUtils.scala From sigmastate-interpreter with MIT License | 5 votes |
package scalan import scalan.util.FileUtil import org.scalactic.TripleEquals import org.scalatest.{Inside, Matchers, TestSuite} def isCI = sys.env.get("CI").flatMap(toBoolean).getOrElse(false) private def toBoolean(s: String): Option[Boolean] = scala.util.Try(s.toBoolean).toOption def pendingOnCI(): Unit = if (isCI) { pending } private val _currentTestName = new ThreadLocal[String] override def withFixture(test: NoArgTest) = { _currentTestName.set(test.name) val outcome = super.withFixture(test) _currentTestName.set(null) outcome } protected def currentTestName: String = { val testName = _currentTestName.get() assert(testName != null, "currentTestName called outside a test") testName } protected def currentTestNameAsFileName: String = FileUtil.cleanFileName(currentTestName) }
Example 9
Source File: FlywayWithMySQLSpecSupport.scala From akka-ddd-cqrs-es-example with MIT License | 5 votes |
package com.github.j5ik2o.bank.adaptor.util import java.io.File import scala.concurrent.duration._ import com.github.j5ik2o.scalatestplus.db._ import com.wix.mysql.distribution.Version._ import org.scalatest.TestSuite trait FlywayWithMySQLSpecSupport extends FlywayWithMySQLdOneInstancePerSuite with RandomPortSupport { this: TestSuite => override protected lazy val mySQLdConfig: MySQLdConfig = MySQLdConfig( version = v5_6_21, port = Some(temporaryServerPort()), userWithPassword = Some(UserWithPassword("bank", "passwd")), timeout = Some((30 seconds) * sys.env.getOrElse("SBT_TEST_TIME_FACTOR", "1").toDouble) ) 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 = "bank")) override protected def flywayConfig(jdbcUrl: String): FlywayConfig = FlywayConfig( locations = Seq( "filesystem:tools/flyway/src/test/resources/db-migration" ), placeholderConfig = Some( PlaceholderConfig(placeholderReplacement = true, placeholders = Map("engineName" -> "MEMORY", "idSequenceNumberEngineName" -> "MyISAM")) ) ) }