scalatest

Strange exception in SBT test

家住魔仙堡 提交于 2019-12-23 05:26:34
问题 I am facing an issue with SBT (version 0.13.9). One of my ScalaTest tests fails not deterministic with EOFException . Stack trace: Exception in thread "Thread-155" Exception in thread "Thread-159" java.io.EOFException at java.io.ObjectInputStream$BlockDataInputStream.peekByte(ObjectInputStream.java:2601) at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1319) at java.io.ObjectInputStream.readObject(ObjectInputStream.java:371) at sbt.React.react(ForkTests.scala:114) at sbt

How can I use MockitoSugar to mock an object (singleton) method?

元气小坏坏 提交于 2019-12-23 04:32:26
问题 Is there a way in scala to use MockitoSugar in order to mock a method of an object that is a scala singleton? 回答1: Your best bet to deal with singletons for mocking is to first do a little rework on the structure of the singleton itself. Use a trait to define the operations and then have the object extend the trait like so: trait Fooable{ def doFoo:String = "foo" } object Foo extends Fooable Then, in any class that needs the Foo object, declare it as an input or something that can be set (DI)

Disable scalatest logging statements when running tests from maven

无人久伴 提交于 2019-12-22 07:58:27
问题 What is the method to disable logging on the scalatest log4j messages: The log4j.properties is as follows: log4j.rootLogger=INFO,CA,FA #Console Appender log4j.appender.CA=org.apache.log4j.ConsoleAppender log4j.appender.CA.layout=org.apache.log4j.PatternLayout log4j.appender.CA.layout.ConversionPattern=%d{HH:mm:ss.SSS} %p %c: %m%n log4j.appender.CA.Threshold = INFO #File Appender log4j.appender.FA=org.apache.log4j.FileAppender log4j.appender.FA.append=false log4j.appender.FA.file=target/unit

Setting up actions for multiple test folders in SBT

痞子三分冷 提交于 2019-12-22 04:27:13
问题 In relation to a previous question, I'd like to have multiple test folders for different types of test and be able to execute the tests contained in each folder with a separate SBT action. For example, an action 'test-unit' would run only the tests contained under the folder src/test/scala/unit , and a 'test-functional' action would run only the tests under src/test/scala/functional . How would we write actions to do this? 回答1: If you are using xsbt 0.10.0, you can easily create additional

How make tests always run in same order in Scalatest?

白昼怎懂夜的黑 提交于 2019-12-22 02:00:00
问题 We use Spec trait for our tests in ScalaTest. when we run the entire suite, it does not always run in the same order. Most answers in google suggest defining a Suite and specifying all the test names. But this requires us to add the test name every time we add a new test. Is it possible to use the DiscoverySuite itself and define the test execution order? Like run the tests in alphabetical order. I looked at extending the DiscoverySuite but DiscoverySuite seems to be private to scalatest. --

ScalaTest Run Configuration in Eclipse: cannot find Suite Class

北城以北 提交于 2019-12-21 12:37:13
问题 Problem: I cannot setup Run Configurations to run scalatest for the Scalatests in my project. Steps to reproduce: Right click on Scala Suite and click on Run as -> Run configurations.. On the left, I see a configuration template for ScalaTest. I click on New and fill the Name but it cannot find the suite-class. Note: It is mentioned here that I should see Run as -> ScalaTest - Suite but I do not see that option. I tried using context menu in the editor, and in the package explorer Steps taken

Access ScalaTest test name from inside test?

為{幸葍}努か 提交于 2019-12-21 04:08:35
问题 Is it possible to access the name of the currently executing test, from within a ScalaTest test? (And how would I do it?) Background: I'm testing that my Data Access Object eventually throws an OverQuotaException if a user e.g. creates too many pages. These tests take rather long to run. To feel happier, I'd like to print the progress to stdout — and since there are quite many tests, I'd like to include the test name in the output, so I know what test is currently being run. (I didn't find

Run ScalaTest tests in parallel

雨燕双飞 提交于 2019-12-21 03:28:11
问题 Given the following test suite: class ParallelizeMe extends FunSuite with BeforeAndAfterAll { override def beforeAll() = println("before") override def afterAll() = println("after") test("test 1") { println("1a") Thread.sleep(3000) println("1b") } test("test 2") { println("2a") Thread.sleep(1000) println("2b") } } How can I run the tests (via sbt) in parallel? Ideally, I want the order of execution to produce the following on stdout: before 1a 2a 2b 1b after 回答1: Use ParallelTestExecution and

Why does Spark fail with “Failed to get broadcast_0_piece0 of broadcast_0” in local mode?

﹥>﹥吖頭↗ 提交于 2019-12-21 02:34:16
问题 I'm running this snippet to sort an RDD of points, ordering the RDD and taking the K-nearest points from a given point: def getKNN(sparkContext:SparkContext, k:Int, point2:Array[Double], pointsRDD:RDD[Array[Double]]): RDD[Array[Double]] = { val tuplePointDistanceRDD:RDD[(Double, Array[Double])] = pointsRDD.map(point => (DistanceUtils.euclidianDistance(point, point2), point)) sparkContext.parallelize(tuplePointDistanceRDD.sortBy(_._1).map(_._2).take(k)) } Using just one SparkContext in my

How to run all scalatest of a multi-modules sbt with intellij?

寵の児 提交于 2019-12-20 12:09:34
问题 I can run: a specific scala test either by right clicking on the test and choose run or if I have run it once previously, by selecting the test in run menu > run... I can run all junit tests by making a new run/debug configuration > + > junit > test kind = all in package > search for tests = in whole project I can run all scalatest (or junit) of one sub-project: right click on the project > run > scalatest in [module name] But if I do the same as (2) with a scala test (+ > scala test > test