Last active
August 29, 2015 14:27
-
-
Save nelanka/9f151cbb0aa33fc796c9 to your computer and use it in GitHub Desktop.
Scala Test Tips
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Retry until it succeeds | |
class ExampleSpec extends FlatSpec with Eventually { | |
eventually { | |
futureInt.get shouldBe 1 | |
} | |
} | |
// Extended patience for integration tests | |
class ExampleSpec extends FlatSpec with Eventually with IntegrationPatience { | |
eventually { | |
futureInt.get shouldBe 1 | |
} | |
} | |
// Wait for a future to complete rather than try repeatedly until it succeeds as in 'eventually' | |
class ExampleSpec extends FlatSpec with ScalaFutures { | |
whenReady(futureInt) { i => | |
i should be(1) | |
} | |
} | |
// Get option values with meaningful errors | |
class ExampleSpec extends FlatSpec with OptionValues { | |
optString.value shouldBe "Hello" | |
} | |
// Look inside nested structures | |
case class Address(street: String, city: String, state: String, zip: String) | |
case class Name(first: String, middle: String, last: String) | |
case class Record(name: Name, address: Address, age: Int) | |
class ExampleSpec extends FlatSpec with Inside { | |
inside (rec) { case Record(name, address, age) => | |
inside (name) { case Name(first, middle, last) => | |
first should be ("Sally") | |
middle should be ("Ann") | |
last should be ("Jones") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment