4. Start with the tests!
If I needed to Add 1 + 1
Clear Lines Consulting 揃 clear-lines.com 11/8/2011 揃 4
5. If I needed to Add 1 + 1
[Test]
public void When_Adding_One_Plus_One_Answer_Should_Be_Two()
{
// Assert
var expectedResult = 2;
Assert.That(actualResult, Is.EqualTo(expectedResult));
}
I would expect the answer to be 2
Clear Lines Consulting 揃 clear-lines.com 11/8/2011 揃 5
6. If I needed to Add 1 + 1
[Test]
public void When_Adding_One_Plus_One_Answer_Should_Be_Two()
{
// Act
var actualResult = calculator.Add(1, 1);
// Assert
var expectedResult = 2;
Assert.That(actualResult, Is.EqualTo(expectedResult));
}
I would need a Calculator
Clear Lines Consulting 揃 clear-lines.com 11/8/2011 揃 6
7. If I needed to Add 1 + 1
[Test]
public void When_Adding_One_Plus_One_Answer_Should_Be_Two()
{
// Arrange
var calculator = new Calculator();
// Act
var actualResult = calculator.Add(1, 1);
// Assert
var expectedResult = 2;
Assert.That(actualResult, Is.EqualTo(expectedResult));
}
I would need some code
Clear Lines Consulting 揃 clear-lines.com 11/8/2011 揃 7
8. If I needed to Add 1 + 1
Does the code work?
Clear Lines Consulting 揃 clear-lines.com 11/8/2011 揃 8
10. Its not about Testing
損 Its about writing Code that works, now
損 Imagine you had implemented the feature
損 then implement it
損 Rinse & Repeat until you have no test to write
Clear Lines Consulting 揃 clear-lines.com 11/8/2011 揃 10
11. Why should you care?
Clear Lines Consulting 揃 clear-lines.com 11/8/2011 揃 11
12. The dreaded L word
息 www.dilbert.com
Clear Lines Consulting 揃 clear-lines.com 11/8/2011 揃 12
13. To me, legacy code is
simply code without
tests.
Michael Feathers,
Working Effectively with Legacy Code
Clear Lines Consulting 揃 clear-lines.com 11/8/2011 揃 13
14. Did I break everything?
Clear Lines Consulting 揃 clear-lines.com 11/8/2011 揃 14
15. Tests: a Vise holding your code steady
Clear Lines Consulting 揃 clear-lines.com 11/8/2011 揃 15
16. A good test is
損 Fast
損 Focused
損 Replicable
損 Automated
Clear Lines Consulting 揃 clear-lines.com 11/8/2011 揃 16
17. Refactoring: improve the
code structure, without
changing its external
behavior.
Clear Lines Consulting 揃 clear-lines.com 11/8/2011 揃 17
18. Red, Green, Refactor
損 Red: write a little test
that doesnt work
損 Green: make the test
work quickly
損 Refactor: cleanup time!
Clear Lines Consulting 揃 clear-lines.com 11/8/2011 揃 18
19. Test-Driven Development is a
way of managing fear during
programming.
Kent Beck,
Test-Driven Development by Example
Clear Lines Consulting 揃 clear-lines.com 11/8/2011 揃 19
20. The Cast
損 Me: Mathias Brandewinder
mathias@clear-lines.com (clear-lines.com/blog)
損 Frameworks/Tools
NUnit: www.nunit.org
xUnit: xunit.codeplex.com/
Resharper: www.jetbrains.com/resharper/
損 Books
Kent Beck, Test Driven Development by Example
Michael Feathers, Working Effectively with Legacy
Code
Roy Osherove, The Art of Unit Testing
Clear Lines Consulting 揃 clear-lines.com 11/8/2011 揃 20