scalatest

Does Scalatest have any support for assumptions?

老子叫甜甜 提交于 2019-12-09 18:25:31
问题 As per the title, I'm wondering if it's possible to provide "assumptions" to Scalatest when defining a particular test case. Assumptions in this context would be preconditions for a test, such that if the assumption evaluated to false, the test would be skipped rather than executed (and handled accordingly by the runners). In this particular case, I'm thinking about dependencies between tests - so there might be a basic test that validates whether a method returns anything at all , followed

Akka异步通讯《three》译

倖福魔咒の 提交于 2019-12-09 17:25:17
异步通讯 Actors是被动的和消息驱动的,Actors在收到消息之前不会做任何事,使用异步消息进行通信。这确保发送方不会停留在等待其消息由接收者处理。相反,发送者将消息发送到收件人的邮箱中,并可以自由地进行其他工作。Actors的邮箱本质上是一个具有排序语义的消息队列。从同一个Actor发送的多个消息的顺序保存下来,但是可以与其他Actor发送的消息交织在一起。 您可能会想知道当Actors不是处理消息时,即在实际工作时,在做什么?它处于一个悬浮状态,它不消耗除内存之外的任何资源。再次显示出Actors的轻量级、高效的性质。 发送消息给Actor 要将消息放到Actors邮箱里,使用ActorRef的“!(bang)方法”。例如,helloworld的主类将消息发送给类似于此的Greeter Actor: Greeter Actor也发消息给Printer Actor:printerActor ! Greeting(greeting) 我们已经研究了如何创建Actor和发送消息。现在,让我们通过对主要类的整体进行回顾。 helloworld中的主类创建并控制了Actors。注意使用一个ActorSystem作为容器和使用actorOf创建Actors。最后,该类发送消息给Actors。 同样地,让我们再看看定义Actors和接受的消息的完整源代码( 详细代码 )。

Using the “should NOT produce [exception]” syntax in ScalaTest

穿精又带淫゛_ 提交于 2019-12-09 14:03:48
问题 I'am toying with Specs2 and ScalaTest for BDD in Scala. I've written expectations in Specs2 when I am asserting that a given exception should not be thrown. "do something" in { { .... } must not(throwA[MyException]) } I was hoping to be able to write the equivalent in ScalaTest like: "do something" in { evaluating { .... } should not produce[MyException] } But this does not compile and I could not find way of doing it. Is that even possible? Many thanks in advance. 回答1: This is not possible

Why “could not find implicit” error in Scala + Intellij + ScalaTest + Scalactic but not from sbt

折月煮酒 提交于 2019-12-09 02:28:01
问题 I have this code that is working 100% from sbt , executing sbt test but throw a compilation error in Intellij Idea. import org.scalatest.{BeforeAndAfter, FunSuite, GivenWhenThen} class SimpleTest extends FunSuite with GivenWhenThen with BeforeAndAfter { test("Simple Test") { Given("Why this error?") assert("ok" === "ok") } } The error is: Error:(5, 10) could not find implicit value for parameter pos: org.scalactic.source.Position Given("Why this error?") Error:(5, 10) not enough arguments for

Scalatest Maven Plugin “no tests were executed”

五迷三道 提交于 2019-12-08 16:47:25
问题 I'm trying to use scalatest and spark-testing-base on Maven for integration testing Spark. The Spark job reads in a CSV file, validates the results, and inserts the data into a database. I'm trying to test the validation by putting in files of known format and seeing if and how they fail. This particular test just makes sure the validation passes. Unfortunately, scalatest can't find my tests. Relevant pom plugins: <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire

ScalaTest - testing equality between two floating point arrays with error margin

杀马特。学长 韩版系。学妹 提交于 2019-12-08 16:37:38
问题 Let's say I have a function that returns a array of doubles. I want to test this function and have calculated the correct value by hand. However since it's floating point numbers, I can't do direct comparisons so is there any sweet syntax by ScalaTest that makes me able to compare double arrays with an epsilion/error margin? Thanks 回答1: Well as I feared there is no nice syntax in ScalaTest for this, and I will accept my own answer with a very basic solution. val Eps = 1e-3 // Our epsilon val

ScalaTest v3: why require to implement convertToLegacyEqualizer

纵饮孤独 提交于 2019-12-08 15:50:02
问题 Using ScalaTest 3.0.0 Environment: Scala 2.11.8, sbt 0.13.5, IntelliJ 14.1.4 build.sbt has only // NOTE: not using org.scalactic libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.0" % "test" The test below passed. However, IntelliJ marks a squiggly red line below MyMiniTest with the warning message: Class 'MyMiniTest ' must either be declared abstract or implement abstract member 'convertToLegacyEqualizer[T](left: T): TripleEqualsSupport.this.LegacyEqualizer[T]' in 'org.scalactic

embedmongo with reactivemongo process does not exit

耗尽温柔 提交于 2019-12-08 02:39:36
问题 I am trying to do some tests using ScalaTest + embedmongo + reactivemongo but I fail. My first problem is that after a test mongod process does not shut down, I have this message in console: INFO: stopOrDestroyProcess: process has not exited and tests are paused till I kill the process manually. That happens even if body of my test is empty. I am running windows 8.1. The other issue is, that when I try to connect to db inside test using reactive mongo and insert anything to db I get this

Hive configuration for Spark integration tests

馋奶兔 提交于 2019-12-08 00:51:55
问题 I am looking for a way to configure Hive for Spark SQL integration testing such that tables are written either in a temporary directory or somewhere under the test root. My investigation suggests that this requires setting both fs.defaultFS and hive.metastore.warehouse.dir before HiveContext is created. Just setting the latter, as mentioned in this answer is not working on Spark 1.6.1. val sqlc = new HiveContext(sparkContext) sqlc.setConf("hive.metastore.warehouse.dir", hiveWarehouseDir) The

Scala, PlayFramework, Mockito, ExecutionContext null

人盡茶涼 提交于 2019-12-07 11:49:31
问题 Following this answer: https://stackoverflow.com/a/30806548/4496364 I use Play's ExecutionContext in my project. Recently I needed to use Mockito to test some services in Play. So, this is simplified version of it: import scala.concurrent.{ Future, ExecutionContext } import play.api.libs.concurrent.Execution.Implicits.defaultContext case class Model(id: Int, name: String) trait DAO { def findAll(implicit ec: ExecutionContext): Future[List[Model]] } class Service(dao: DAO) { def findAll: