I've done this workshop multiple times at work to teach developers Test Driven Development using C# and NUnit.
You can clone it at https://github.com/fincher42/TDDWorkshopNunit.git
The theme of the workshop is from the movie "We Bought A Zoo".
Enjoy and leave me feedback below on how to improve the workshop.
Here's an outline of my notes:
Essence of TDD: Write failing tests **first**, before coding the functionality.
- Bob writes a failing test
- Ashley writes just enough functionality in the method so it will pass.
- The code may then be refactored to make it cleaner.
- Bob and Ashley now switch roles and continue.
This is the Red/Green/Refactor cycle.
One method of arranging your code is to have Arrange/Act/Assert sections in your test.
Benefits of Test Driven Development:
- Encourages better architectural design
- Makes debugging easier
- Guarantees tests are written
- Encourages us to think about requirements and edge cases
- Let's you be courageous and refactor code
Drawbacks of Test Driven Development:
- Tests are expensive. They are expensive to write and more expensive to maintain.
- Perfect Unit Tests with 100% coverage do not offer any guarantees on overall code quality. Don't be lulled into a sense of false security.
- GUI, Integration, Performance, and Endurance tests are also needed.