Testing in Scala

Book description

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.

Table of contents

  1. Testing in Scala
  2. Preface
    1. Audience
    2. Organization of This Book
    3. About the Book
    4. Test-Driven Development
    5. Conventions Used in This Book
    6. Using Code Examples
    7. How to Contact Us
    8. Acknowledgments
  3. 1. Setup
    1. Setup in Mac OS X, Mac OS X Lion, and Linux
    2. Setup in Windows
    3. Using SBT
    4. SBT Folder Organization
    5. The Build File
    6. About Our Examples
    7. Creating Our Examples Using TDD, ScalaTest, and SBT
  4. 2. Structure and Configuration of Simple Build Tool (SBT)
    1. Directories in SBT
    2. The Importance of Good Infrastructure
      1. Triggered Executions
    3. What If I Need an Extra Repository?
    4. Format of Dependencies Line
    5. Updating Changes from the Build File
      1. Bringing Some Sources and Documentation
    6. Running SBT
      1. From the Shell
      2. Interactive Mode
    7. Basic Tasks
      1. Using the Scala Interpreter
    8. Knowing Your History
      1. Conclusion
  5. 3. ScalaTest
    1. Setting up ScalaTest in SBT
    2. Matchers
      1. Types of Matchers
        1. Simple matchers
        2. String matchers
        3. Relational operator matchers
        4. Floating-point-matchers
        5. Reference matchers
        6. Iterable matchers
        7. Seq and traversable matchers
        8. Map matchers
        9. Compound matchers
        10. Property matchers
        11. java.util.Collection matchers
      2. MustMatchers
    3. Exception Handling
    4. Informers
    5. GivenWhenThen
    6. Pending Tests
    7. Ignoring Tests
    8. Tagging
      1. Running Tags From the Command Prompt
      2. Running Tags in SBT
    9. Specifications
      1. FunSpec
      2. WordSpec
      3. FeatureSpec
      4. FreeSpec
      5. FlatSpec
      6. JUnitSuite
      7. TestNGSuite
    10. Fixtures
      1. Anonymous Objects
      2. Fixture Traits
      3. OneInstancePerTest
      4. Before and After
  6. 4. Specs2
    1. Setting Up Specs2 in SBT
    2. Unit Specification
    3. Matchers
      1. Simple Matchers
      2. String Matchers
      3. Relational Operator Matchers
      4. Floating-Point Matchers
      5. Reference Matchers
      6. Iterable Matchers
      7. Seq and Traversable Matchers
      8. Map Matchers
      9. XML Matchers
      10. Partial Function Matchers
      11. Other Matchers
    4. Acceptance Specification
      1. Chaining Tests
      2. Given/When/Then
    5. Data Tables
    6. Tagging
    7. Fixtures
  7. 5. Mocking
    1. EasyMock
      1. EasyMock with ScalaTest
    2. Mockito
      1. Mockito with Specs2
        1. Order verification
    3. ScalaMock
      1. Mocking Traits
      2. Mocking Classes
      3. Mocking Singleton Objects
      4. Mocking Companion Objects
      5. Mocking Functions
      6. Mocking Finals
  8. 6. ScalaCheck
    1. Properties
    2. Constraining Properties
    3. Grouping Properties
      1. Custom Generators
    4. Arbitrary
    5. Labeling
    6. ScalaCheck with ScalaTest
      1. Generators
    7. ScalaCheck with Specs2
  9. Colophon
  10. Copyright

Product information

  • Title: Testing in Scala
  • Author(s):
  • Release date: January 2013
  • Publisher(s): O'Reilly Media, Inc.
  • ISBN: 9781449315115