scalatest

Handling Doubles in ScalaTest

混江龙づ霸主 提交于 2019-12-18 07:44:26
问题 I have just started using ScalaTest and I am using the following to compare two Doubles in my spec as follows: it should "calculate the price" in { val x = new X(10,10,12,1000) assert(x.price() === 185.92) } The spec is passing even though I have put in a wrong value of 185.92 to compare against what the price function is returning (that actually returns 10.23 for the case above). I have other specs where I just compare Ints and they work as expected. But the ones involving Doubles are

ScalaTest in sbt: is there a way to run a single test without tags?

烈酒焚心 提交于 2019-12-17 15:05:05
问题 I know that a single test can be ran by running, in sbt, testOnly *class -- -n Tag Is there a way of telling sbt/scalatest to run a single test without tags? For example: testOnly *class -- -X 2 it would mean "run the second test in the class. Whatever it is". We have a bunch of tests and no one bothered to tag them, so is there a way to run a single test without it having a tag? 回答1: This is now supported (since ScalaTest 2.1.3) within interactive mode: testOnly *MySuite -- -z foo to run

Class is not visible unless I declare it in a package

ぐ巨炮叔叔 提交于 2019-12-13 18:12:41
问题 I have a class AppComponents in AppLoader.scala in projectDir/app My tests are in projectDir/test/ControllerSpec/UserControllerSpec.scala In UserControllerSpec.scala , I tried to create an instance of AppComponents but the compiler couldn't find the AppComponents class override def components: BuiltInComponents = new AppComponents(context) //doesn't compile But if I include statement package app in Apploader.scala then the compiler is able to find AppComponents and the above code compiles. I

Limit scalatest parallel execution thread number

雨燕双飞 提交于 2019-12-13 15:27:23
问题 I'm trying to execute some part of my tests in parallel so I've extended those tests classes with ParallelTestExecution trait, the only problem is that it runs too many tests at once. As I understand it runs up to 2 * number_of_cpu_cores so in my case 2*8 tests. Its way too much and I would like to limit it to 4 threads max. I've tried to use SBT concurentRestrictions in Test settings but it wont change anything (I thing it affects only concurrent test classes execution and do not affect

object scalatest is not a member of package org

送分小仙女□ 提交于 2019-12-13 12:26:57
问题 I want to write some tests for my toy project in scalatest. As I use sbt I installed scalatest via libraryDependencies += "org.scalatest" %% "scalatest" % "2.0.M5" % "test" in my project root's build.sbt . Then I created test class in src/test/scala : package parsers import org.scalatest.FunSuite class BaseParserSuite extends FunSuite { test("test works") { val result = 2 assert(result === 2) } } I run it via sbt test and it works. But the annoying thing is that on line 3 with import org

ScalaTest - writing custom matchers

橙三吉。 提交于 2019-12-12 07:59:47
问题 I am running into a problem while writing a custom matcher for NodeSeq: private def matchXML(expected: NodeSeq) = new Matcher[NodeSeq] { def apply(left: NodeSeq): MatchResult = MatchResult(left xml_== expected, "XML structure was not the same (watch spaces in tag texts)", "XML messages were equal") } This compiles, but the following piece of code: val expected : NodeSeq = ... val xml : NodeSeq = ... xml should matchXML(expected) causes: error: overloaded method value should with alternatives:

Unable to create stub with Array argument in ScalMock

a 夏天 提交于 2019-12-12 04:49:40
问题 Here is an example of what I try to achieve. Stub always retuns null, but if I change Array(1L) to * it works. It seems there is a problem with array arguments. trait Repo { def getState(IDs: Array[Long]): String } "test" should "pass" in { val repo = stub[Repo] (repo.getState _).when(Array(1L)).returns("OK") val result = repo.getState(Array(1L)) assert(result == "OK") } 回答1: See this post: Why doesn't Array's == function return true for Array(1,2) == Array(1,2)? ScalaMock is working fine,

SBT - using two versions of library in a single project?

可紊 提交于 2019-12-12 03:45:48
问题 I have a project with a bunch of tests written for Scalatest 1.x, which use the ShouldMatchers class, which was deprecated in version 2.x. Going forward, I want to use version 2 for new tests, but this will mean I have to refactor all my existing tests (which I can do, but it'll take some time). In the meantime, is there a way in SBT to compile existing classes against Scalatest 1.x, and new ones against Scalatest 2.0? Or more generally, compile some classes in a project against a different

How to resolve version conflicts in IntelliJ SBT included libraries

不问归期 提交于 2019-12-12 02:57:21
问题 I am using ScalaTest 2.2.1 in my project but some dependency I use brings in ScalaTest 1.9.2 . In SBT, this causes no proble. It compiles and runs all tests. In IntelliJ, the test show the in with "cannot resolve symbol in" although it still compiles. Hoever the test runner dies with" An exception or error caused a run to abort: org.scalatest.FlatSpecLike$$anonfun$1$$anon$2 cannot be cast to org.scalatest.words.ResultOfStringPassedToVerb If I manually remove ScalaTest 1.9.2 from the External

Is there a ScalaTest Plugin for Eclipse Luna and Scala IDE Lithium?

雨燕双飞 提交于 2019-12-11 20:59:30
问题 Trying to find the ScalaTest plugin for use with Eclipse Luna and Scala IDE for Eclipse 4.0.0 (aka Lithium). Currently using Milestone 2 of the Scala IDE for Eclipse Lithium plugin. The ScalaTest plugin used to be part of the Scala IDE for Eclipse plugin (appeared on the list and you could check the box it to install--Scala IDE for Eclipse is supposed to be an ecosystem of plugins, ScalaTest being one of them). It doesn't appear to be there any more. It's not on the list, When I check