Testing in Scala

By Daniel Hinojosa

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

If you construct your Scala software via Test-Driven improvement, you’ll fast see the benefits of checking out earlier than you write construction code. This hands-on e-book exhibits you the way to create exams with ScalaTest and the Specs2—two of the easiest trying out frameworks available—and how you can run your assessments within the uncomplicated construct software (SBT) designed in particular for Scala projects.

By development a pattern electronic jukebox software, you’ll realize the way to isolate your exams from huge subsystems and networks with mocking code, and the way to take advantage of the ScalaCheck library for computerized specification-based checking out. If you’re acquainted with Scala, Ruby, or Python, this booklet is for you.
Get an outline of Test-Driven Development
Start an easy undertaking with SBT and create exams earlier than you write code
Dive into SBT’s simple instructions, interactive mode, packaging, and history
Use ScalaTest either within the command line and with SBT, and include JUnit and TestNG
Work with the Specs2 framework, together with Specification kinds, matchers DSLs, and information Tables
Understand mocking by utilizing Java frameworks EasyMock and Mockito, and the Scala-only framework ScalaMock
Automate trying out through the use of ScalaCheck to generate faux information

Show description

Quick preview of Testing in Scala PDF

Best Development books

Introduction to Programming Using Python plus MyProgrammingLab with Pearson eText -- Access Card

Notice: prior to deciding to buy, discuss with your teacher to make sure you choose the right kind ISBN. numerous models of Pearson's MyLab & getting to know items exist for every identify, and registrations usually are not transferable. To sign up for and use Pearson's MyLab & gaining knowledge of items, you can even want a path identification, which your teacher will offer.

Ground Control: Fear and Happiness in the Twenty-First-Century City

Whilst the figures say crime is falling, why are we extra worried than ever? may well our cities and towns be growing worry and distrust? extra estate is being in-built Britain than at any time because the moment international warfare - yet it really is owned through inner most businesses, designed for revenue and watched over by means of CCTV.

The Dragon's Gift: The Real Story of China in Africa

Is China a rogue donor, as a few media pundits recommend? Or is China assisting the constructing global pave a pathway out of poverty, because the chinese language declare? within the previous couple of years, China's relief application has leapt out of the shadows. Media reviews approximately large relief applications, aid for pariah regimes, regiments of chinese language hard work, and the ruthless exploitation of staff and normal assets in many of the poorest nations on this planet sparked fierce debates.

The Coming Prosperity: How Entrepreneurs Are Transforming the Global Economy

Ours is the main dynamic period in human historical past. some great benefits of 4 centuries of technological and organizational swap are ultimately achieving a formerly excluded worldwide majority. this modification will create large-scale possibilities in richer international locations just like the usa simply because it has in poorer international locations now within the ascent.

Extra resources for Testing in Scala

Show sample text content

This could show EasyMock to count on your expectation within the order that you just supply in the course of practice session on your try out. Now that every mock has rehearsed its half, it’s time to rewind the habit by means of calling replay, calling persist at the topic below attempt jukeboxStorageService, and verifying the implications. package deal com. oreilly. testingscala import org. scalatest. matchers. MustMatchers import org. scalatest. Spec import org. easymock. EasyMock. _ category JukeboxStorageServiceEasyMockSpec extends Spec with MustMatchers { describe("A Jukebox garage Service") { it("should use effortless mock to mock out the DAO classes") { //previous line passed over for brevity //replay, extra like rewind replay(daoMock) //make the decision jukeboxStorageService. persist(jukeBox) //verify that the calls anticipated have been made verify(daoMock) } } } replay rewinds all of the mocks to got down to practice the prescribed activities we rehearsed. jukeboxStorageService. persist is the particular name to the try out, because it sends in a jukeBox concrete item. The final line verifies that the mocks acted out what was once meant. working the try now will lead to failure, with a purpose to now paintings on pleasing the try out. a couple of minutes later, possibly whatever just like the following instance will be what the JukeboxStorageService type would favor with the habit that satisfies the attempt. src/main/scala/com/oreilly/testingscala/JukeboxStorageService. scala. package deal com. oreilly. testingscala type JukeboxStorageService(dao:DAO) { def persist(jukeBox:JukeBox) { jukeBox. albums. getOrElse(Nil). foreach{ album => dao. persist(album) album. acts. foreach(act => dao. persist(act)) } } } The persist strategy, a minimum of for this implementation, will get the entire albums, if there are any. getOrElse is a technique on choice that returns the contents of Some—in this situation an inventory of albums—or generates an empty checklist Nil if there are not any albums. The forEach process, working at the go back price of getOrElse, iterates throughout the checklist of albums. album => dao. persist(album) takes each one album from the albums record and calls persist at the DAO. eventually, for each act linked to the album, every one may be despatched to dao for patience. operating the JukeboxStorageServiceEasyMockSpec will now be successful. > test-only com. oreilly. testingscala. JukeboxStorageServiceEasyMockSpec [info] Compiling 1 Scala resource to /home/danno/testing_scala_book. svn/testingscala/target/scala-2. nine. 1/classes... [info] JukeboxStorageServiceEasyMockSpec: [info] A Jukebox garage carrier [info] - may still use effortless mock to mock out the DAO sessions [info] handed: : overall 1, Failed zero, error zero, handed 1, Skipped zero [success] overall time: nine s, accomplished Jan 7, 2012 11:12:34 PM This advent to EasyMock has no longer been particular to Scala, considering that this expertise has been used for years in Java. EasyMock does comprise particular help for ScalaTest, which bargains more straightforward how one can paintings EasyMock. EasyMock with ScalaTest ScalaTest deals an EasyMockSugar trait that turns replaying and verifying into behind-the-scenes affairs, letting the try out developer concentrate on the practice session and working the attempt.

Download PDF sample

Rated 4.15 of 5 – based on 13 votes