Unit Testing 101


Published on

Unit Testing 101 presented at ESRI Developer Summit, March 24th, 2009. This talk reviews the key concepts of unit testing, the technologies used by DTSAgile in out development projects.

Published in: Technology
  • Dear sir: I am a diploma holder in NIIT Shimoga at the year 1996 with micro soft office, excel, and power-point as main subjects. Long before i am familiar with C & Java programming Though self study courses. Now i am finding it difficult to follow Unit Testing 101 & Unit testing and Test automation. Can u help me.
    Awaiting for early reply.
    Thanks and regards.

    Send it to mohamedshukoor2000@gmail.com
    Are you sure you want to  Yes  No
    Your message goes here
  • Well done for such difficult subject manner.
    Are you sure you want to  Yes  No
    Your message goes here
  • one of the best presentation I've seen so far at the dev summit
    Great job. Thanks.
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Total Views
On Slideshare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Unit Testing 101

  1. You need some tests yo! Dave Bouwman // CTO // DTSAgile
  2. the “big” ideas
  3. prove code works
  4. prove design works
  5. catch regression
  6. unit testing 101
  7. Instantiate class under test… Call Method… Check Results… Call Method… Check Results…
  8. good tests are… independent repeatable self-contained* professional
  9. good tests are… focused
  10. tools!
  11. “unit testing on crack” Scott Hanselman www.hanselman.com
  12. writing tests
  13. simple methods with simple signatures mean simple tests
  14. complex methods with complex signatures mean… complex tests
  15. most ArcObjects applications fall in this category
  16. for testing design we must
  17. separation of concerns
  18. a class has single purpose
  19. stay inside its box
  20. user interface (events + logic + data access)
  21. private void ButtonOn_Click(){ //read values from controls //apply business logic //connect to database //update data //update interface }
  22. user interface objects business objects data access objects
  23. Private void ButtonOn_Click(){ //read values from controls //apply business logic //send changes to DAL //connect to database //update data //update interface }
  24. n-tier architecture
  25. user interface WPF/Silverlight objects business objects unit tests data access objects
  26. design patterns yo
  27. model view controller
  28. ASP.NET MVC released!! http://asp.net/mvc
  29. dependency management
  30. dependencies
  31. 1 created by the constructor
  32. private IAccountRepository _accountRepository; private IFormsAuthentication _formsAuthentication; private ILogService _logger; public AccountController() { _accountRepository = new AccountRepository(_connectionString); _logger = new Logger(); _formsAuthentication = new FormsAuthentication(); }
  33. what about testing
  34. good tests are… independent repeatable self-contained* professional
  35. “tight coupling” external dependencies in the tests
  36. internal dependencies
  37. and separate them
  38. 2 pass dependencies into the constructor
  39. dependency injection
  40. private IAccountRepository _accountRepository; private IFormsAuthentication _formsAuthentication; private ILogService _logger; public AccountController(IAccountRepository accountRepository, IFormsAuthentication formsAuthentication, ILogService logger) { _accountRepository = accountRepository; _formsAuthentication = formsAuthentication; _logger = logger; }
  41. pushed the problem up a level
  42. inversion of control
  43. I need an AccountController! configuration Global.asax.cs
  44. Castle Windsor Spring.NET mvccontrib IoC StructureMap Unity http://mvccontrib.codeplex.com
  45. back to unit testing…
  46. isolated testing
  47. & mock fakes stubs
  48. code you wrote generated on-the-fly
  49. fake objects
  50. stub/mock objects
  51. tools!
  52. rhinomocks http://ayende.com/projects/rhino-mocks.aspx
  53. ArcMap development
  54. not our box
  55. separate logic from wiring
  56. emulate events fromArcMap
  57. my code sinks…
  58. in ArcMap Business IEditEvents Shim Logic ArcMap
  59. under test Business Test Logic
  60. test your code not ESRI’s
  61. ArcEngine Applications
  62. it’s our box
  63. design matters.
  64. ArcGIS Server
  65. testing Web ADF…
  66. custom services
  67. COM Utilities SOC COM Utility WebService ArcGIS Server
  68. Server Object Extensions SOC SOE WebService ArcGIS Server
  69. testable classes IServerObjectExtension COM COM SOE Utility Utility (ArcObjects) (ArcObjects)
  70. but i’m too cool for COM…
  71. jsunit D.O.H. Unit Testing FlexUnit Silverlight Harness
  72. http://mbunit.com http://testdriven.net resources http://ASP.NET/mvc http://mvccontrib.codeplex.com http://castleproject.org http://ayende.com/projects/rhino-mocks.aspx
  73. i’m in teh codez writin teztz!
  74. and nao u can too!
  75. http://blog.davebouwman.net dbouwman@dtsagile.com questions http://twitter.com/dbouwman http://slideshare.com/dbouwman
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.