Unit Testing Succinctly

Unit Testing Succinctly

By Marc Clifton Foreword by Daniel Jebaraj Copyright © 2013 by Syncfusion Inc. 2501 Aerial Center Parkway Suite 200 Morrisville, NC 27560 USA All rights reserved. I mportant licensing information. Please read. This book is available for free download from www.syncfusion.com on completion of a registration form. If you obtained this book from any other source, please register and download a free copy from www.syncfusion.com. This book is licensed for reading only if obtained from www.syncfusion.com. This book is licensed strictly for personal or educational use. Redistribution in any form is prohibited. The authors and copyright holders provide absolutely no warranty for any information provided. The authors and copyright holders shall not be liable for any claim, damages, or any other liability arising from, out of, or in connection with the information in this book. Please do not use this book if the listed terms are unacceptable. Use shall constitute acceptance of the terms listed. SYNCFUSION, SUCCINCTLY, DELIVER INNOVATION WITH EASE, ESSENTIAL, and .NET ESSENTIALS are the registered trademarks of Syncfusion, Inc. Technical Reviewer: Praveen Ramesh, director of development, Syncfusion, Inc. Copy Editor: Mary Brunnemer Acquisitions Coordinator: Jessica Rightmer, senior marketing strategist, Syncfusion, Inc. Proofreader: Graham High, content producer, Syncfusion, Inc. Table of Contents About the Author ....................................................................................................................................... 13 Introduction ............................................................................................................................................... 14 Code Examples ...................................................................................................................................... 14 Screenshots ...................................................................................................................................... 14 Expectations of the Reader.................................................................................................................... 14 Organization of this Book ....................................................................................................................... 14 Chapter 1 Why Unit Test? ....................................................................................................................... 16 Measuring Correctness .......................................................................................................................... 16 Repetition, Repetition, Repetition .......................................................................................................... 17 Code Coverage ...................................................................................................................................... 17 Chapter 2 What is Unit Testing? ............................................................................................................. 18 What is a Unit? ....................................................................................................................................... 18 Pure Units ......................................................................................................................................... 18 Dependent Units ............................................................................................................................... 22 What is a Test? ...................................................................................................................................... 23 Normal Conditions Testing ............................................................................................................... 23 Abnormal Conditions Testing ........................................................................................................... 24 Unit Tests and Other Testing Practices ................................................................................................. 24 Acceptance Test Procedures ........................................................................................................... 25 Automated User Interface Testing .................................................................................................... 25 Usability and User Experience Testing ............................................................................................. 26 Performance and Load Testing ........................................................................................................ 26 Chapter 3 Proving Correctness .............................................................................................................. 27 How Unit Tests Prove Correctness ........................................................................................................ 27 Prove Contract is Implemented ........................................................................................................ 27 Prove Computational Results ........................................................................................................... 28 Prove a Method Correctly Handles an External Exception .............................................................. 32 Prove a Bug is Re-creatable ............................................................................................................. 34 Prove a Bug is Fixed ......................................................................................................................... 34 Prove Nothing Broke When Changing Code .................................................................................... 35 Prove Requirements Are Met ........................................................................................................... 35 Chapter 4 Strategies for Implementing Unit Tests .............................................................................. 37 Starting From Requirements .................................................................................................................. 37 Prioritizing Computational Requirements ......................................................................................... 37 Select an Architecture ....................................................................................................................... 38 Maintenance Phase .......................................................................................................................... 38 Determine Your Process ........................................................................................................................ 39 Test-Driven Development ................................................................................................................. 39 Code First, Test Second ................................................................................................................... 41 No Unit Tests .................................................................................................................................... 41 Balancing Testing Strategies ............................................................................................................ 42 Chapter 5 Look before You Leap: The Cost of Unit Testing ................................................................ 43 Unit Test Code vs. Code Being Tested ................................................................................................. 43 Unit Test Code Base May Be Larger Than Production Code........................................................... 43 Maintaining Unit Tests ........................................................................................................................... 44 Does Unit Testing Enforce an Architecture Paradigm? ......................................................................... 44 Unit Test Performance ........................................................................................................................... 45 Mitigating Costs ..................................................................................................................................... 45 Correct Inputs ................................................................................................................................... 45 Avoiding Third-party Exceptions ....................................................................................................... 46 Avoid Writing the Same Tests for Each Method ............................................................................... 47 Cost Benefits .......................................................................................................................................... 47 Coding to the Requirement ............................................................................................................... 47 Reduces Downstream Errors............................................................................................................ 47 Test Cases Provide a Form of Documentation................................................................................. 47 Enforcing an Architecture Paradigm Improves the Architecture....................................................... 47 Junior Programmers ......................................................................................................................... 48 Code Reviews ..................................................................................................................................

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    128 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us