Tools are not enough. If you want to succeed overtime, you need more ammunition. Some people call them best practices. We call them real life lessons.Why should every developer unit test his code, Unit testing tools,TDD & Unit testing best practices, How to avoid writing fragile tests and Testing special scenarios
2. Who am I? Software Developer Part time blogger http://blog.drorhelper.com/@dhelper One thing was the same wherever I worked…
3. Agenda Unit tests - what, how and why Tools of the trade How to write better tests Writing tests when it’s hard to test
4. Sounds familiar? Every ten bugs I fix I create a new one… I have no idea what caused that issue… I’d rather not change that function… It is impossible to unit test our project! Setting my test environment takes too long
6. Unit tests Unit Tests Test specific functionality Clear pass/fail criteria Good unit test runs in isolation
7. What is a Unit Test Unit tests [TestMethod] public void CheckPassword_ValidUser_ReturnTrue() { bool result = CheckPassword(“user”, “pass”); Assert.IsTrue(result); }
8. What is a Unit Test Unit tests [Test] public void CheckPassword_ValidUser_ReturnTrue() { bool result = CheckPassword(“user”, “pass”); Assert.That(result, Is.True); }
9. The kind of test Unit tests should be: Small Atomic Test a single functional unit Isolated! Integration tests are used to test system wide functionality Unit tests
10. Why use automated unit tests? Quick feedback Regression Gain control of your code Unit tests
12. Tools of the trade Tools Server Source Control Build Server Build Script Dev Machine Test Runner Unit Testing Framework Isolation Framework Code Coverage
19. Development environment Make it easy to write and run tests Unit test framework Test Runner Isolation framework Know where you stand Code coverage Tools
20. Unit testing frameworks NUnit xUnit MSTest Gallio (MbUnit) NBehave List of unit testing frameworks: http://en.wikipedia.org/wiki/List_of_unit_testing_frameworks Tools
35. Avoid over specification Write better tests Don’t test private/internal (most of the time) Fake as little as necessary Test only one thing (most of the time)
36. Testing the un-testable First - better understand the problem Isolation framework Design/refactor for Testability Reflection Use integration tests Testing un-testable
38. Resources This Week In Test webcast www.typemock.com/this-week-in-test/ Book: The art of unit testing Typemock insider’s blog: blog.typemock.com Follow us on twitter @typemock
Notas do Editor
Software project should not be a ticking bomb.
AtomicRepeatableNo dependency between tests/test orderClear pass/fail criteria
The backbone of TDD (and development)Show how CI & script runner run the test suite – perhaps publish results to web