The Artima Developer Community
Sponsored Link

ScalaTest/ScalaUtils Forum
AsyncFeatureSpec list of Assertions

5 replies on 1 page. Most recent reply: Feb 1, 2017 4:36 AM by Carvel Baus

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 5 replies on 1 page
Carvel Baus

Posts: 4
Nickname: carvel
Registered: Jan, 2017

AsyncFeatureSpec list of Assertions Posted: Jan 30, 2017 11:28 AM
Reply to this message Reply
Advertisement
I am trying the following:


scenario("test multiple futury things") {

val futureChanges = someService.doSomethingFutury(List(somethings))

futureChanges.map { changes =>
changes.map { change => assert(change.contains("someString")) }
}
}


The issue is that the scenario expects a single Future[Assertion] but I have a List[Future[Assertions]] in this case.

Is it possible to test each item in the list indiviually within a single scenario?


Bill Venners

Posts: 2284
Nickname: bv
Registered: Jan, 2002

Re: AsyncFeatureSpec list of Assertions Posted: Jan 30, 2017 12:02 PM
Reply to this message Reply
Sorry can you clarify what the types are by putting a type annotation on the futureChanges val?

Carvel Baus

Posts: 4
Nickname: carvel
Registered: Jan, 2017

Re: AsyncFeatureSpec list of Assertions Posted: Jan 30, 2017 12:38 PM
Reply to this message Reply
Apologies...


scenario("test multiple futury things") {

val futureChanges:List[Future[String]] = someService.doSomethingFutury(List(somethings))

futureChanges.map { changes =>
changes.map { change => assert(change.contains("someString")) }
}
}

Carvel Baus

Posts: 4
Nickname: carvel
Registered: Jan, 2017

Re: AsyncFeatureSpec list of Assertions Posted: Jan 30, 2017 2:22 PM
Reply to this message Reply
I stumbled across the "succeed" val which I was able to place at the end of the scenario and make the compiler happy. This just seemed less than eloquent, although it effectively worked.

The test does fail if any Future does not resolve as successful.

Bill Venners

Posts: 2284
Nickname: bv
Registered: Jan, 2002

Re: AsyncFeatureSpec list of Assertions Posted: Jan 30, 2017 7:06 PM
Reply to this message Reply
If you put succeed at the end, I think the test will always succeed. Succeed means succeed. So I'm not sure why you would see the test failing, but regardless I don't think it is doing what you think it is doing.

Regardless, what I'd suggest is to take your List[Future[String]] and change that to a Future[List[String]], like this:


val listOFutureChanges: List[Future[String]] =
someService.doSomethingFutury(List(somethings))

val futureListOfChanges: Future[List[String]] =
Future.sequence(listOfFutureChanges)


Then can map an assertion about the list of changes onto that single outer future, like this:


import org.scalatest.Inspectors._

futureListOfChanges map { changes =>
forAll (changes) { change =>
assert(change.contains("someString"))
}
}

Carvel Baus

Posts: 4
Nickname: carvel
Registered: Jan, 2017

Re: AsyncFeatureSpec list of Assertions Posted: Feb 1, 2017 4:36 AM
Reply to this message Reply
Thanks Bill, that helped a lot.

Flat View: This topic has 5 replies on 1 page
Topic: Quick Start Example Compilation Failure Previous Topic   Next Topic Topic: TestFailedException should be an error and not a RuntimeException

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use