Unit Test Frameworks: Tools for High-Quality Software Development

Unit Test Frameworks: Tools for High-Quality Software Development

Paul Hamill

Language: English

Pages: 216

ISBN: B0026OR3H6

Format: PDF / Kindle (mobi) / ePub


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.

Professional C# 6 and .NET Core 1.0

Introduction to Compiler Design (Undergraduate Topics in Computer Science)

Practical Ruby Gems

Thinking Functionally with Haskell

Common LISP: A Gentle Introduction to Symbolic Computation

 

 

 

 

 

 

 

 

 

 

{ public void testGetBook( ) { MockDBConnection mock = new MockDBConnection( ); LibraryDB db = new LibraryDB( mock ); Book book = db.getBook( "Cosmos", "Carl Sagan" ); assertTrue( mock.validate( ) ); } } The test method testGetBook( ) creates an instance of MockDBConnection, uses it to construct a LibraryDB, and then calls the LibraryDB method getBook( ). The success of the test depends on the result of the mock’s validate( ) function. If the mock is in the expected state, its validation

is closed. Aside from fixing the bug, this process has the additional benefit of creating a test that will catch it. If the bug is ever re-introduced, the test will fail and highlight the problem. By following the TDD cycle, you can come as close as humanly possible to writing flawless code on the first tryin other words, “code once.” The process gives you a clear indication that a piece of work is done. When a new unit test is written and then fails, the task is halfway completed. You cannot

assertXpathValuesNotEqual(String controlXpath, String testXpath, Document document) assertXpathValuesNotEqual(String controlXpath, String testXpath, String inXMLString) Assert that the evaluation of two XPaths in the same DOM Document or XML string are not equal. Chapter 11. Resources Unit testing is a constantly evolving technology, as are unit testing tools. This section lists some of the most useful written and electronic resources for learning more about unit testing and for

TestFixtureTearDown attributes, Usage TestRunner modified to run, Step 1: Test adding a Book to a Library LibraryTests class (example), TestSuite as a TestSuite, xUnit Architecture Summary creating TestSuite, Usage PyUnit test fixture, Usage running with TextTestRunner, Usage LibraryXMLDoc class (example), Usage LibraryXMLDocTest class (example), Usage licenses, open source software BSD license for XMLUnit, Overview Common Public License, Overview GNU Lesser

failure, the framework skips the rest of the code in the test method, since the test result is already known. BookTest tests the class Book , shown in Example 3-2. Example 3-2. The class Book Book.java public class Book { private String title = ""; Book(String title) { this.title = title; } String getTitle( ) { return title; } } This is the Book class developed in Chapter 2, with a few changes. The title attribute is now private and the accessor function getTitle( ) is added. BookTest

Download sample

Download