Best Practices:
- Test Behavior, Not Methods
- Apply the "Too Simple to Break" Rule
- Use Object-Oriented Best Practices In Your Test Cases
- Use Appropriate Method Names
- Don’t Use Try/Catch Blocks to Catch Unexpected Exceptions
- Don’t Rely on Visual Inspection
- Use A Code Coverage Tool
- Use The Appropriate Tool for the Testing Scenario
- Write the test first, then the code.
- Design classes using dependency injection.
- Separate UI code from its behavior using Model-View-Controller or Model-View-Presenter.
- Do not write static methods or classes. Reason: Static methods are difficult or impossible to isolate and Rhino Mocks is unable to mock them.
- Program off interfaces, not classes. Reason: Interfaces can be easily mocked using Rhino Mocks and other mocking frameworks.
- Isolate external dependencies. Reason: Unresolved external dependencies cannot be tested.
- Mark as virtual the methods you intend to mock. Reason: Rhino Mocks is unable to mock non-virtual members.
Tools:
- FITNESSE - Acceptance Testing
- FIT.NET - Acceptance Testing
- Concordion.NET - Acceptance Testing
- SPRING.NET
- Mocking: NMock, RhinoMocks, Typemock
- MbUnit: A unit testing framework - e.g. for database integration test
- NUnit: a simple unit testing framework
- NDbUnit
- WatiN: UI testing
- csUnit
- FXCop: code analysis tool
- NDepend: dependency analysis tool
- NCover
- Story Teller
- xBehave
- Test Runners: TestDriven.NET, Resharper, TeamCity
- HtmlAgilityPack: for HTTP acceptance tests
Process of TDD:
- Receive requirement/feature as a User Story
- Write scenarios and behaviours of the feature in the Given/When/Then format. You'd need to be good at identifying behaviours/scenarios of a certain feature.
- Create your first test fixture and write a test method which tests a behaviour. You write the test to a non-existent Type. You'd need to be good in identifying which classes would need to be created; of course you can refactor later if you have time.
- Use Resharper to generate the non-existent class.
- Write enough code so that your code compiles
- Run the test and see it fails
- Write enough production code so that the test of the certain behaviour passes
- Refactor the production code and test code both.
- Go to 2 and cover more scenarios.
More Info:
No comments:
Post a Comment