Test Driven Development TDD Test Driven Development
Different Approaches To Testing White box Testing Unit Testing Block box Testing Beta Testing Regression Testing Acceptance Testing Usability Testing Integration Testing Functional Testing System Testing Stress Testing Performance Testing
Unit Test Unit testing is a software development process in which the smallest testable parts of an application, called units, are individually and independently scrutinized for proper operation. Unit testing can be done manually but is often automated.
Test Driven Development Process that uses unit tests to drive the design of software.
Different Kinds of Testing Tools MSTest – Official unit tester created by Microsoft xUnit – Open source unit tester developed for .NET NUnit – Open source unit testing framework inspired by Java’s Junit
The mantra of TDD is RGR
Test First vs Test Last
Robert C.Martin’s Laws No production code until you’ve written a failing test. Write no more in your unit test then enough to make it fail. Write no more production code than enough to make it pass.
Mocking Frameworks FackItEasy – Mocking framework where objects are considered fakes but usage determines whether they are mocks or stubs. NSubstitute – Mocking framework syntax that is more succinct and concise. Moq – Mocking library developed from scratch to take full advantage of .NET.
Creating your first Unit Test Remember the Three-A’s pattern A pattern for arranging and formatting code in Unit Test methods
Asserting the facts
Assembly Initialize
Class Initialize and Class cleanup
Test Initial and Test Cleanup
Debugging Unit Test Unit tests can be debugged just like any other code. Break points can be set anywhere in your code To pause at breakpoints you have to explicitly run tests in debug mode.
MSTest.exe Used for execution of unit tests from command line Located under “\common7\IDE” Command line options: Command Line Option Description /testcontainer: [file name] All test in the assembly (container) /test: [test name] A single test /testlist: [test list path] A test list /testsettings A specify a test settings file
Run unit tests with your builds Run tests after every build on VS(Local): Running unit tests after every build is supported in Visual Studio Enterprise. To run your unit tests after each local build, choose Test on the standard menu, and then choose Run Tests After Build on the Test Explorer toolbar. Run tests after every build on TFS(Server): Running unit tests after every build is supported in TFS. To run your unit tests after each build, register Build Definitions with agent on the build menu from TFS and run Queue build that you created for Build.
Summary TDD DRY YAGNI KISS Test First and Test Last Build with Test Red – Green – Refactor DRY Don’t repeat yourself YAGNI You aren’t gonna need it KISS Keep it short and simple Test First and Test Last Build with Test 3A Pattern Debugging Unit Test For more details go to www.omidnasri.com