Your SlideShare is downloading. ×
Real Life Unit Testing
Real Life Unit Testing
Real Life Unit Testing
Real Life Unit Testing
Real Life Unit Testing
Real Life Unit Testing
Real Life Unit Testing
Real Life Unit Testing
Real Life Unit Testing
Real Life Unit Testing
Real Life Unit Testing
Real Life Unit Testing
Real Life Unit Testing
Real Life Unit Testing
Real Life Unit Testing
Real Life Unit Testing
Real Life Unit Testing
Real Life Unit Testing
Real Life Unit Testing
Real Life Unit Testing
Real Life Unit Testing
Real Life Unit Testing
Real Life Unit Testing
Real Life Unit Testing
Real Life Unit Testing
Real Life Unit Testing
Real Life Unit Testing
Real Life Unit Testing
Real Life Unit Testing
Real Life Unit Testing
Real Life Unit Testing
Real Life Unit Testing
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Real Life Unit Testing

3,494

Published on

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, …

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

Published in: Technology, Education
3 Comments
4 Likes
Statistics
Notes
No Downloads
Views
Total Views
3,494
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
0
Comments
3
Likes
4
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide
  • 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
  • Transcript

    • 1. Real life unit testing
      Dror Helper
    • 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
    • 5. Avoid stupid bugs
    • 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
    • 11. Avoid stupid bugs
      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
    • 13. Continuous Integration
      Tools
      What’s new?
      Commit
      Build Server
      (TeamCity)
      There you go
      Start working
      Build artifacts
      We automatically got
      Source Control
      (SVN)
      Build Agents
      (FinalBuilder)
    • 17. Build Script at a Glance
      Tools
    • 18. TeamCity at a Glance
      Tools
    • 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
    • 21. Test Runners
      Tools
    • How to write better tests
      Write better tests
      Write easy to understand tests
      Reuse code where appropriate
      Running test should be easy
      Avoid fragile tests
      Trust Your Tests!
    • 26. Readability is important
      Why did the test fail?
      Avoid unnecessary debugging
      Understand what the test does!
      Write better tests
    • 27. Easy to understand unit tests
      Names are important
      Don’t be afraid to repeat yourself
      Arrange-Act-Assert
      Or Act-Assert-Arrange
      Write better tests
    • 28. Write readable tests
      Test only one thing (most of the time)
      KISS – avoid logic in your test
      Write better tests
    • 29. Duplicate code problem
      Write better tests
      After refactoring I need to re-write my tests.
      Writing the same code twice is wrong
    • 30. Reuse code
      Create objects using factories
      Manipulate and configure initial state
      Run common tests in common methods
      Write better tests
    • 31. Just remember
      Readability is important
      - It’s still ok to repeat yourself
      Write better tests
    • 32. Easy to run
      Running the tests takes too long
      Setting complicated testing environment
      Write better tests
    • 33. Test should be easy to run
      Integration vs. Unit tests
      Simple configuration
      Use fakes
      Write better tests
    • 34. Fragile tests
      Tests fail every time I change my code
      Write better tests
    • 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
    • 37. Unit tests = avoid stupid bugs
    • 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

    ×