Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

5 unit testing facts I wish I know 7 years ago

1,696 views

Published on

Getting started with unit tests should be simple – it’s just a matter of writing code to test other code. If that’s right why so many talented developers fail implementing unit tests in their daily job. I’ve started using unit tests 8 years ago and failed miserably. It took me 2 years and the right company to start over and learn how to properly use unit tests and TDD as development tools. In this talk I’ll cover the non-trivial facts I learnt about unit testing and the tips that I use to this day.

Published in: Software
  • SECRET: Men usually out of emotion, not logic. Take advantage of this and get your Ex back today! See how at:  http://ishbv.com/exback123/pdf
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

5 unit testing facts I wish I know 7 years ago

  1. 1. 5 7 @dhelper
  2. 2. OzCode (a.k.a “Magical debugging”) Evangelist http://blog.drorhelper.com
  3. 3. code code code Debug Crash == 0 ‘it works!’
  4. 4. 100 little bugs in the code 
  5. 5. Write test Is test passing? Try and Fix Test Other tests passing? Download NUnit Are we done yet? Coffee [Test] public void AddTest() { var cut = new MyClass(); var result = cut.Func(“abc”, 3); Assert.AreEqual(5, result); }
  6. 6. And Nobody cared  Conclusion: stop writing tests
  7. 7. Success (and Failure) depends on environment not only depends on how you write tests #1
  8. 8. Build server Dev machines Team Project
  9. 9. Source Control Build Server Commit There you go What’s new? BuildAgents
  10. 10. TheTeam •The team commitment is important •Everybody does it •Learn from test reviews •Track & publish results
  11. 11. Code GO Code Code Code Code Code Code Code Code Code Code Test
  12. 12. Class Unit #2
  13. 13. ¯_(ツ)_/¯ Acceptance tests  requirements Unit tests  Micro requirements • technical detail you can explain to your peers • May require some trail & error
  14. 14. Not all tests are unit tests #3
  15. 15. Server Comm Client UITestFake Comm
  16. 16. [Test] public async Task GetTextsWhenServerDownloadFail() { // Who am I??? var result = await _surveyService.GetTextsAsync(); Assert.IsFalse(result.HasError); Assert.NotNull(result.TheResult); }
  17. 17. Code duplication is ok (usually) #4
  18. 18. Unit testing is not about writing tests #5
  19. 19. × Test123 × CustomerTest × PerchaseOrderTestNew × MoveBatteryVanilla  CalculateTax_InvalidYear_LogErrorToFile  OrdersShouldBeCreated  OrdersWithNoProductsShouldFail
  20. 20. "1234567890".Should().Be("0987654321"); Expected string to be "0987654321", but "1234567890" differs near "123" (index 0).
  21. 21. Early feedback Safety net Refactoring Design Validate requirements Change your code without fear
  22. 22. Thank you drorh@codevalue.net http://blog.drorhelper.com

×