Test Driven .NET Development with FitNesse second edition Gojko Adzic Test Driven .NET Development with FitNesse: second edition Gojko Adzic Copy-editor: Marjory Bisset Cover picture: Brian Samodra Published 2009 Copyright © 2008-2009 Neuri Limited Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where these designations appear in this book, and the publisher was aware of a trademark claim, the designations have been printed with initial capital letters or in all capitals. The author has taken care in the preparation of this book, but makes no expressed or implied warranty of any kind and assumes no responsibility for errors or omissions. No liability is assumed for incidental or consequential damages in connection with or arising out of the use of the information or programs contained herein. All rights reserved. This publication is protected by copyright, and permission must be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permissions, write to: Neuri Limited 25 Southampton Buildings London WC2A 1AL United Kingdom You can also contact us by e-mail: [email protected] Register your book online Visit http://gojko.net/fitnesse and register your book online to get free PDF updates and notifications about corrections or future editions of this book. ISBN: 978-0-9556836-2-6 REVISION:2009-12-08 Preface to the second edition ........................................................... vii What's new in this version? ..................................................... vii Training and consultancy ................................................................ ix Acknowledgements ......................................................................... xi About the author ........................................................................... xiii I. Getting started .............................................................................. 1 1. Introduction ......................................................................... 3 Who should read this book? .............................................. 3 Why bother with TDD? .................................................... 4 Beyond unit tests .............................................................. 6 Getting FIT ...................................................................... 7 FitNesse or NUnit? ........................................................... 9 The next step .................................................................. 12 2. Installing FitNesse ............................................................... 15 Setting up FitNesse ......................................................... 16 A quick test .................................................................... 17 How FitNesse connects to .NET classes ............................ 22 Don't forget the test ........................................................ 23 Playtime ......................................................................... 25 II. FitNesse and TDD in practice ..................................................... 27 3. Our Project ......................................................................... 29 Lottery rules ................................................................... 29 Selected user stories ........................................................ 29 Applying TDD to our project .......................................... 30 The next step .................................................................. 39 4. Writing basic tests ............................................................... 41 ColumnFixture — the Swiss Army knife of FitNesse ........ 43 Testing in plain English .................................................. 47 Playtime ......................................................................... 51 5. Writing simple test scripts ................................................... 53 Passing values between tables .......................................... 54 Writing a simple test script ............................................. 56 Use data-transfer objects directly .................................... 59 Using symbols to check dynamic values ........................... 61 Checking for errors ......................................................... 62 Playtime ......................................................................... 64 6. Writing efficient test scripts ................................................ 67 Better test scripts with DoFixture .................................... 69 iii Test Driven .NET Development with FitNesse Use DoFixture keywords for better control ...................... 73 Keep ActionFixture in mind ............................................ 75 Playtime ......................................................................... 76 7. Removing duplication ......................................................... 79 Group related tests into test suites ................................... 79 Include pages and use them as components ..................... 82 Reuse entire suites with symbolic links ............................ 83 Use markup variables to parameterise test pages .............. 84 Defining common actions ............................................... 85 Remove irrelevant information ....................................... 86 Acceptance tests should focus on business rules ............... 88 Hide parts of the page ..................................................... 88 Playtime ......................................................................... 88 8. Coordinating fixtures .......................................................... 91 Embed fixtures for best results ........................................ 92 Use SetUpFixture to prepare the stage for tests ................ 94 Create test suites in flow mode ........................................ 99 Wrapping business objects with DoFixture .................... 101 Playtime ....................................................................... 102 9. Working with collections ................................................... 103 Testing lists of objects ................................................... 104 Checking for empty collections ...................................... 108 Beware of test extensions ............................................... 109 Use RowFixture for better precision .............................. 111 Playtime ....................................................................... 114 III. Advanced FitNesse usage ......................................................... 117 10. Working in a team ........................................................... 119 Options for team setup .................................................. 119 Organising the files ....................................................... 123 Integrating with automated build tools .......................... 127 11. Testing web interfaces ..................................................... 135 Choosing the right thing to test ..................................... 135 Introducing Selenium ................................................... 138 Connecting from FitNesse ............................................. 142 Running tests on a remote server ................................... 147 More Selenium tests ...................................................... 149 12. Testing database code ...................................................... 151 Connecting to the database ........................................... 151 iv Working with stored procedures ................................... 155 Preparing test data ........................................................ 156 Executing statements .................................................... 157 Verifying query results .................................................. 157 Other DbFit features ..................................................... 158 13. Testing legacy code .......................................................... 161 Covering legacy code with tests ..................................... 161 Use blank cells to print out results ................................. 162 Use show and check with FitLibrary ............................... 163 Wrap existing objects for tests ....................................... 163 Use ArrayFixture and RowFixture to capture data batches ......................................................................... 164 Using existing forms for regression tables ...................... 165 14. Using business domain objects directly ............................ 169 System under test with ColumnFixtures ........................ 169 Changing the system under test ..................................... 170 Using collections directly .............................................. 172 Setting the system under test from FitNesse ................... 174 Using named fixtures .................................................... 175 Don't go too far ............................................................ 175 15. Tips and tricks ................................................................. 177 What really happens during a test? ................................ 177 Attaching the Visual Studio debugger ............................ 182 Load non-standard cell operators for simpler comparis- ons ............................................................................... 183 Simplify verifications
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages278 Page
-
File Size-