Testing in Scala

Testing in Scala

Daniel Hinojosa

Language: English

Pages: 165

ISBN: 1449315119

Format: PDF / Kindle (mobi) / ePub

Daniel Hinojosa, "Testing in Scala" English | ISBN: 1449315119 | 2013 | Publisher: O’Reilly Media | PDF | 166 pages | 6 + 1 MB

If you build your Scala application through Test-Driven Development, you’ll quickly see the advantages of testing before you write production code. This hands-on book shows you how to create tests with ScalaTest and the Specs2—two of the best testing frameworks available—and how to run your tests in the Simple Build Tool (SBT) designed specifically for Scala projects.

By building a sample digital jukebox application, you’ll discover how to isolate your tests from large subsystems and networks with mocking code, and how to use the ScalaCheck library for automated specification-based testing. If you’re familiar with Scala, Ruby, or Python, this book is for you.
Get an overview of Test-Driven Development
Start a simple project with SBT and create tests before you write code
Dive into SBT’s basic commands, interactive mode, packaging, and history
Use ScalaTest both in the command line and with SBT, and learn how to incorporate JUnit and TestNG
Work with the Specs2 framework, including Specification styles, matchers DSLs, and Data Tables
Understand mocking by using Java frameworks EasyMock and Mockito, and the Scala-only framework ScalaMock
Automate testing by using ScalaCheck to generate fake data

Cleft Lip and Palate : Diagnosis and Management (3rd Edition)

Pro Website Development and Operations: Streamlining DevOps for large-scale websites

Privatizing China: Socialism from Afar

Lucene in Action: Covers Apache Lucene 3.0 (2nd Edition)

Temptations of the West: How to Be Modern in India, Pakistan, Tibet, and Beyond

.net [UK] (July 2015)



















Navarro. In practice, using compound matchers will pose some difficulty with the parentheses. Here are some rules to keep in mind when engineering compound assertions. First, parentheses must be included around and and or assertions. Secondly, remember that the righthand assertion must also be wrapped in parentheses. The following line would not compile. redHotChiliPeppers should not contain "The Edge" or contain "Kenny G" To fix the first issue, we apply parentheses around the or assertion.

assertions on those properties. This example checks that the album Blizzard of Ozz was created in 1980 by some chap named Ozzy Osbourne. Assertions can be made to be sure that the title, year, and artist are indeed the ones given at instantiation. It is worth remembering that Artist is a class whose parameters are val, therefore getters are created automatically by Scala and using property assertions will work. It would also work to make all the properties of Artist a var, since var creates both

color, too high, or too low. How does this translate to software? Test-driven development starts with tests, each meant to define a single purpose such as “Write customer data to a database”, “Move a sprite to the corner of screen,” or “Send out notifications that a meeting registration even has occured.” The programmer writes the test using the class in question as if he were a developer using the API. Consider how a user would instantiate the object, etc. What problems would the end user

somewhere and that it occurs in that particular list only one time. The sixth matcher accepts a Boolean function and asserts that every element in the Traversable abides by it. In this case, each element must have a size greater than 5. The last line item matches the Seq on the left side with the Seq on the right side. Map Matchers Using the map of singers to bands shown in MapMatchers of ScalaTest, here are the analogous matchers for Specs2. val map = Map("Jimmy Page" -> "Led

BruceSpringsteenFactory { private lazy val theBoss = { println("loaded the info"); new Artist("Bruce", None, "Springsteen", Nil, Some("The Boss")) } def artist = discography.foldLeft(theBoss) { (boss, album) ⇒ boss.addAlbum(album) } def discography = List( new Album("Greetings from Ashbury Park, N.J.", 1973, None, theBoss), new Album("The Wild, The Innocent\n& the E Street Shuffle", 1973, None, theBoss), new Album("Born To Run", 1975, None, theBoss), new Album("Darkness on the Edge of Town",

Download sample