Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint

Testing services

Interface mappings make it easy to test fails and errors too

Many services have a responsibility to inform the application when something has gone wrong—for example, that contact with the server has been lost and data wasn’t able to be saved. If your service contains its own data paths it can be difficult to test that it behaves correctly in the face of an IOError, but if you inject your paths as dependencies you can configure your test service with a bad url very easily.

This example comes from a different application requiring a connection to a remote server in order to submit usage statistics:

Example 10-4. Dependency Injection makes it easy to switch urls and configurations to verify that our service deals with errors (AsUnit 3 tests)


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint