specs2

how to make scalatest generate html report through sbt

你。 提交于 2020-01-01 02:51:12
问题 The way to do this for specs2 based test in sbt is (testOptions in Test) += Tests.Argument(TestFrameworks.Specs2, "html") but how about scalatest? I've done lots of Google search, but cannot find a good explanation/solution. 回答1: so two things I need to do... I. use any scalatest artifact after 2.0.M5b. For me, I added this dependency, org.scalatest" %% "scalatest" % "2.0.M6" % "test->*" excludeAll ( ExclusionRule(organization="org.junit", name="junit") ) "test->*" is necessary, otherwise

What is the difference between should and must in scala testing? [duplicate]

五迷三道 提交于 2019-12-25 06:28:04
问题 This question already has an answer here : In ScalaTest is there any difference between `should`, `can`, `must` (1 answer) Closed 3 years ago . Both scalatest and Specs2 have separate matchers for should and must . However, I cannot find any explanation for why you would use one or the other. What exactly is the difference? 回答1: There is no difference, this is purely a syntactic preference. I personally prefer to use must in specs2 because I think that should can make people think that an

Specs2 wrap unit test in database transaction

独自空忆成欢 提交于 2019-12-25 04:17:27
问题 I'm updating my application from Specs2 2.3.12 to 3.6.1 and am having trouble updating the class which wraps our unit tests in a transaction. The 2.3.12 class: class DbTx extends AroundOutside[Session] { var session: Option[Session] = None def around[T : AsResult](t: => T) = { Db.withTransaction { implicit s => session = Some(s) val result = AsResult(t) s.rollback() result } } def outside: Session = session.get } its usage: "my unit test" in (new DbTx).apply { implicit session: Session => ...

How to Test a Play Application that extends a custom trait

99封情书 提交于 2019-12-25 04:11:25
问题 I'm having trouble writing tests for a mixin to my Play application that runs in it's own thread separate from play. I've tried over-writing WithApplication.provideApplication method with no luck. I get an inheriting conflicting methods error. (one from the real app "MyRunnableSystemWrapper", one from my mocked fake mixin called "MyMockedSystemWrapper"). execute(system) runs my system that is tested elsewhere and has sideaffects (connects to networked services, thus failing this test when

Scala specs2 mocking a trait method returns always Nullpointer exception

浪子不回头ぞ 提交于 2019-12-23 20:36:01
问题 I have a trait that I want to mock and use that mocked Trait in another Service during testing. The problem is, that I receive a Nullpointerexception when I try to mock the return value of the indexDocuments function. Testmethod: "createDemand must return None if writing to es fails" in new WithApplication { val demandDraft = DemandDraft(UserId("1"), "socken bekleidung wolle", Location(Longitude(52.468562), Latitude(13.534212)), Distance(30), Price(25.0), Price(77.0)) val es = mock

How can i skip a test in specs2 without matchers?

老子叫甜甜 提交于 2019-12-23 09:07:01
问题 I am trying to test some db dependent stuff with specs2 in scala. The goal is to test for "db running" and then execute the test. I figured out that i can use orSkip from the Matcher class if the db is down. The problem is, that i am getting output for the one matching condition (as PASSED) and the example is marked as SKIPPED. What i want instead: Only execute one test that is marked as "SKIPPED" in case the test db is offline. And here is the code for my "TestKit" package net.mycode.testkit

My Play Application's Constructor takes an argument, how do I give a mocked argument at Spec Test?

☆樱花仙子☆ 提交于 2019-12-23 05:11:09
问题 If my play application has something like this: class Foo() extends Bar {} class Application @Inject (f: Foo) extends Controller { def index = Action { OK("Hi, Foo App") } } How do I change my spec test to accept MockedFoo class? @RunWith(classOf[JUnitRunner]) class MockedFoo() extends Bar {} class ApplicationTest(implicit ee: ExecutionEnv) extends Specification { "Sending a GET request to index " should { "Respond with OK " in new WithApplication { //######## Inject MockedFoo val response =

org.specs2.mock.Mockito matchers are not working as expected

佐手、 提交于 2019-12-22 18:52:46
问题 Here is the code I am trying to run: import org.specs2.mock.Mockito import org.specs2.mutable.Specification import org.specs2.specification.Scope import akka.event.LoggingAdapter class MySpec extends Specification with Mockito { "Something" should { "do something" in new Scope { val logger = mock[LoggingAdapter] val myVar = new MyClassTakingLogger(logger) myVar.doSth() there was no(logger).error(any[Exception], "my err msg") } } } When running this, I get the following error: [error] org

Testing a page that is loaded after a redirect

北慕城南 提交于 2019-12-22 11:12:05
问题 I've got a test case that is supposed to verify that, after a POST call, the user is redirected to the correct page. "Redirect Page" in { running(FakeApplication()) { val Some(result) = route(FakeRequest(POST, "/product/add/something") .withFormUrlEncodedBody( "Id" -> "666", ) .withSession("email" -> "User") ) status(result) must equalTo(SEE_OTHER) // contentAsString(result) at this point is just blank This verifies that a redirect URL is given. How do I then get the unit test to go to the

Seq empty test with specs2

心已入冬 提交于 2019-12-22 05:18:14
问题 How can I check if a Seq[String] is empty or not using specs2 in Scala ? I am using seq must be empty or seq.length must be greaterThan(0) but I end up always with type mismatch errors. ret is Seq[String] ret.length must be greaterThan(0) [error] ApiTest.scala:99: type mismatch; [error] found : Int [error] required: org.specs2.matcher.Matcher[String] [error] ret.length must be greaterThan(0) 回答1: I think the type mismatch error is caused by another bit of code than that which you've posted.