You need
         some tests yo!




Dave Bouwman // CTO // DTSAgile
the “big” ideas
prove
 code
    works
prove
design
    works
catch
  regression
unit testing
      101
Instantiate class under test…

           Call Method…

          Check Results…

           Call Method…

          Check...
good tests are…
      independent
        repeatable
            self-contained*
                professional
good tests are…

      focused
tools!
“unit testing
                           on crack”
Scott Hanselman
www.hanselman.com
writing
   tests
simple methods
   with simple signatures



   mean simple tests
complex methods
with complex signatures
   mean…
        complex tests
most
 ArcObjects
  applications
 fall in this
    category
for testing
 design we must
separation
   of concerns
a class has
   single
         purpose
stay
  inside
   its
         box
user interface
  (events + logic + data access)
private void ButtonOn_Click(){

    //read values from controls
    //apply business logic
    //connect to database
    /...
user interface
 objects
business
 objects

data access
 objects
Private void ButtonOn_Click(){

    //read values from controls
    //apply business logic
    //send changes to DAL
    /...
n-tier
 architecture
user interface   WPF/Silverlight
 objects
business
 objects
                 unit
                   tests
data access
 ob...
design
patterns yo
model
 view
 controller
ASP.NET MVC
released!!



        http://asp.net/mvc
dependency
management
dependencies
1
    created
    by the
      constructor
private IAccountRepository _accountRepository;
private IFormsAuthentication _formsAuthentication;
private ILogService _log...
what about
   testing
good tests are…
      independent
        repeatable
            self-contained*
                professional
“tight coupling”



                   external
              dependencies
                     in the
                   ...
internal
dependencies
and
 separate
       them
2   pass
     dependencies
      into the
       constructor
dependency
   injection
private IAccountRepository _accountRepository;
private IFormsAuthentication _formsAuthentication;
private ILogService _log...
pushed
 the
 problem
   up a
     level
inversion
   of control
I need an
AccountController!




                     configuration
                     Global.asax.cs
Castle Windsor
                 Spring.NET
mvccontrib IoC
                 StructureMap

                 Unity




      ...
back to
unit testing…
isolated
 testing
&
mock
 fakes
   stubs
code you
 wrote     generated
            on-the-fly
fake
 objects
stub/mock
objects
tools!
rhinomocks




             http://ayende.com/projects/rhino-mocks.aspx
ArcMap
 development
not
  our
 box
separate
      logic
       from
           wiring
emulate
  events
fromArcMap
my code
  sinks…
in
ArcMap
                               Business
          IEditEvents   Shim
                                Logic


   ...
under
  test
                Business
         Test
                 Logic
test
 your
    code

           not
           ESRI’s
ArcEngine
Applications
it’s
   our
  box
design
 matters.
ArcGIS
 Server
testing
 Web ADF…
custom
services
COM
Utilities
                             SOC

                                   COM
                                   ...
Server
 Object
 Extensions                    SOC

                                     SOE




              WebService

...
testable
 classes
   IServerObjectExtension




       COM                      COM
       SOE
      Utility              ...
but i’m too
 cool for COM…
jsunit

D.O.H. Unit Testing

FlexUnit

Silverlight Harness
http://mbunit.com

            http://testdriven.net

resources   http://ASP.NET/mvc

            http://mvccontrib.codepl...
i’m in teh codez
writin teztz!
and nao u
      can too!
http://blog.davebouwman.net
            dbouwman@dtsagile.com
questions
            http://twitter.com/dbouwman
          ...
Unit Testing 101
Unit Testing 101
Unit Testing 101
Unit Testing 101
Unit Testing 101
Unit Testing 101
Unit Testing 101
Unit Testing 101
Unit Testing 101
Unit Testing 101
Unit Testing 101
Unit Testing 101
Unit Testing 101
Unit Testing 101
Upcoming SlideShare
Loading in...5
×

Unit Testing 101

7,202

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
3 Comments
23 Likes
Statistics
Notes
  • 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.
    shukoor

    Send it to mohamedshukoor2000@gmail.com
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Well done for such difficult subject manner.
       Reply 
    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.
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total Views
7,202
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
393
Comments
3
Likes
23
Embeds 0
No embeds

No notes for slide

Unit Testing 101

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

×