O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Unit Test Frameworks

Book Description

Unit test frameworks are a key element of popular development methodologies such as eXtreme Programming (XP) and Agile Development. But unit testing has moved far beyond eXtreme Programming; it is now common in many different types of application development. Unit tests help ensure low-level code correctness, reduce software development cycle time, improve developer productivity, and produce more robust software.Until now, there was little documentation available on unit testing, and most sources addressed specific frameworks and specific languages, rather than explaining the use of unit testing as a language-independent, standalone development methodology. This invaluable new book covers the theory and background of unit test frameworks, offers step-by-step instruction in basic unit test development, provides useful code examples in both Java and C++, and includes details on some of the most commonly used frameworks today from the XUnit family, including JUnit for Java, CppUnit for C++, and NUnit for .NET.Unit Test Frameworks includes clear, concise, and detailed descriptions of:

  • The theory and design of unit test frameworks
  • Examples of unit tests and frameworks
  • Different types of unit tests
  • Popular unit test frameworks
  • And more
It also includes the complete source code for CppUnit for C++, and NUnit for .NET.

Table of Contents

  1. A Note Regarding Supplemental Files
  2. Preface
    1. Audience
    2. Contents of This Book
    3. Conventions Used in This Book
    4. Using Code Examples
    5. How to Contact Us
    6. Acknowledgments
  3. 1. Unit Test Frameworks: An Overview
    1. 1.1. Test Driven Development
    2. 1.2. Unit Testing and Quality Assurance
    3. 1.3. Homegrown Unit Testing
  4. 2. Getting Started: Tutorial
    1. 2.1. Outline of an Application: the Virtual Library
    2. 2.2. Example 1: Create a Book
      1. 2.2.1. Step 0: Set Up the Unit Test Framework
      2. 2.2.2. Step 1: Create a Unit Test
      3. 2.2.3. Step 2: Create a Book
      4. 2.2.4. Step 3: Test Again
    3. 2.3. Example 2: Create a Library
      1. 2.3.1. Step 1: Test adding a Book to a Library
      2. 2.3.2. Step 2: Add a Book to a Library
      3. 2.3.3. Step 3: Check Unit Test Results
  5. 3. The xUnit Family of Unit Test Frameworks
    1. 3.1. xUnit Family Members
    2. 3.2. xUnit Extensions
    3. 3.3. The xUnit Architecture
      1. 3.3.1. TestCase
      2. 3.3.2. TestRunner
      3. 3.3.3. TestFixture
      4. 3.3.4. TestSuite
      5. 3.3.5. TestResult
    4. 3.4. xUnit Architecture Summary
  6. 4. Writing Unit Tests
    1. 4.1. Types of Asserts
    2. 4.2. Defining Custom Asserts
    3. 4.3. Single Condition Tests
    4. 4.4. Testing Expected Errors
    5. 4.5. (Not) Testing Get/Set Methods
    6. 4.6. Testing Protected Behavior
    7. 4.7. Test Code Organization
    8. 4.8. Mock Objects
    9. 4.9. AbstractTest
    10. 4.10. Performance Tests
    11. 4.11. New Library and Book Code
  7. 5. Unit Testing GUI Applications
    1. 5.1. Library GUI
  8. 6. JUnit
    1. 6.1. Overview
    2. 6.2. Architecture
    3. 6.3. Usage
    4. 6.4. Test Assert Methods
  9. 7. CppUnit
    1. 7.1. Overview
    2. 7.2. Architecture
    3. 7.3. Usage
    4. 7.4. Test Assert Methods
  10. 8. NUnit
    1. 8.1. Overview
    2. 8.2. Architecture
    3. 8.3. Usage
    4. 8.4. Test Assert Methods
  11. 9. PyUnit
    1. 9.1. Overview
    2. 9.2. Architecture
    3. 9.3. Usage
    4. 9.4. Test Assert Methods
  12. 10. XMLUnit
    1. 10.1. Overview
    2. 10.2. Architecture
    3. 10.3. Usage
    4. 10.4. Test Assert Methods
  13. 11. Resources
    1. 11.1. Web Sites
    2. 11.2. Discussion Groups
    3. 11.3. Books
  14. A. Simple C++ Unit Test Framework
    1. A.1. Example 1: Create a Book
      1. A.1.1. Step 0: Set Up the Unit Test Framework
      2. A.1.2. Step 1: Create a Unit Test
      3. A.1.3. Step 2: Create a Book
      4. A.1.4. Step 3: Test Again
    2. A.2. Example 2: Create a Library
      1. A.2.1. Step 1: Test Adding a Book to a Library
      2. A.2.2. Step 2: Add a Book to a Library
      3. A.2.3. Step 3: Check Unit Test Results
  15. B. JUnit Class Reference
    1. Assert
    2. AssertionFailedError
    3. ComparisonFailure
    4. Protectable
    5. Test
    6. TestCase
    7. TestFailure
    8. TestListener
    9. TestResult
    10. TestSuite
  16. C. CppUnit Class Reference
    1. assertion_traits
    2. AutoRegisterSuite
    3. CompilerOutputter
    4. Exception
    5. Exception::Type
    6. ExpectedExceptionTraits
    7. NamedRegistries
    8. NotEqualException
    9. Orthodox
    10. Outputter
    11. RepeatedTest
    12. SourceLine
    13. SynchronizedObject
    14. SynchronizedObject::ExclusiveZone
    15. SynchronizedObject::SynchronizationObject
    16. Test
    17. TestCaller
    18. TestCase
    19. TestDecorator
    20. TestFactory
    21. TestFactoryRegistry
    22. TestFailure
    23. TestFixture
    24. TestFixtureFactory
    25. TestListener
    26. TestResult
    27. TestResultCollector
    28. TestRunner
    29. TestSetUp
    30. TestSucessListener
    31. TestSuite
    32. TestSuiteBuilder
    33. TestSuiteFactory
    34. TextOutputter
    35. TextTestProgressListener
    36. TextTestResult
    37. XmlOutputter
    38. XmlOutputter::Node
  17. Index
  18. About the Author
  19. Colophon
  20. Copyright