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.
Caleb Jenkins
developingUX.com




ProactionMentors.com   @calebjenkins
I’ll be
                leaving
                my
                clothes
                on
CODING Naked!
Development           Engineering          Process
 Object Orientation    Automated Tests     Agile, Lean, XP
       SOLID...
Is TDD
only for
 coding
 elites?
or something for
every developer?
How do we make Automated
          Tests the norm?
make coding without
                tests as
uncomfortable as coding
                  naked
and as fun as playing
          with Legos
* this is not me
Development




…and you build the Legos!
Building Better
  Legos
Do you write after the fact Tests
or design with executable
specifications?

A test confirms what was done
blue prints or ...
What was
  What
should be
            Discuss:                  done
  done
            Building Inspector
               ...
what are the 4 big parts of unit tests?



16
Code            Tests




     Test Framework   Test Runner


17
your application
           Code
     what you want to test
                                Tests




     Test Framework ...
your test code
                        the code that tests the
         Code                   Tests
                     ...
Code                   Tests


     attributes and asserts
      the framework provides
     the attributes and asserts
  ...
Code                 Tests


                          runs the tests
                      often associated with the
    ...
Code            Tests




     Test Framework   Test Runner


22
Test Runner
            Tests




                             Test Framework
            Tests
     Code
            Test...
1   Have a runner
Pick a Test
1   Framework
Test Framework




27
Pick a Test
2   Runner
Test Runners




     nUnit Test Runner




29
Test Runners




     nUnit Test Runner
     Visual Studio (VS Test)


30
Test Runners




     nUnit Test Runner
     Visual Studio (VS Test)

          CodeRush / ReSharper
31
Test Runners




     nUnit Test Runner
     Visual Studio (VS Test)

         CodeRush / ReSharper
32      Continuous Int...
Write Test
3   Code
Test Code … 3 A’s
 Arrange                       Act                      Assert

Arrange– Set up the scenario and the ini...
Building better Lego’s
    UI
           UI Logic                           Tests are small
App Domain      Domain Validat...
Simple Tests (return values)               with no dependencies…
                             Test Runner
                ...
Demo
Let’s write
some tests!
2         Set the Scene

context makes all the difference!
Discussion
Defining Behavior

   as a <role>,
 I will <function>
 so that <value>
Discussion
what if our “tests”

 given <class> to test
when <setup> scenario
should <test> outcome

     matched our
     ...
Discussion
    BDD
Resources & Frameworks
                                                                BDD
     more than TDD done right
 ...
3   Handle your
    dependencies
Dependencies
“The single greatest thing that you can do
to make your code more testable and
healthy is to start taking a D...
How do you test this
    UI
           UI Logic

App Domain      Domain Validation

         Integration      Service Prox...
UI
           UI Logic

App Domain      Domain Validation

         Integration      Service Proxy
                  Data ...
Test Runner
                         Test Code

     UI Logic
App Domain      Domain Validation

     Integration         ...
Note:
Dependency Injection
  will turn you in to a complete
  coding Ninja, however the
  full scope of DI with any of
  t...
http://developingUX.com/DI/
Mocking Framework
“A mocking framework allows you to create fake classes on
the fly in-line with your test code. That is a...
Mocking in .NET
Bringing DI together
IData mockData = MockRepository.GenerateMock<IData>();

mockData.Expect(x => x.getAll<account>())
           .Return(sampl...
IData mockData = MockRepository.GenerateMock<IData>();

mockData.Expect(x => x.getAll<account>())
           .Return(sampl...
IData mockData = MockRepository.GenerateMock<IData>();

mockData.Expect(x => x.getAll<account>())
           .Return(sampl...
Demo
Mocking




          Confidential
the problem with edges
UI   Business   Data
Edges are
      Hard to Test




UI   Business        Data
Testing edges
can be like
testing to see if
you’re good at
cliff jumping



                    Confidential
That’s not me
       Confidential
You’re either an
expert and it works…


     ..or you’re
     stuff on a rock.
                 Confidential
Edges are
      Hard to Test




UI    UI Data
     Business        Data
     Logic
         Logic
Edges are still
                  Edges are
                  Hard to Test




                                          D...
Edges are still
                  Edges are
                  Hard to Test




                                          D...
MVC
 MVP
M-V-VM
         72
MVC
 MVP
M-V-VM
         73
Model View Controller (MVC)
• All input is routed to a controller
• Example Web Scenarios
• ASP.NET MVC Framework
 Model V...
Application
          UI Layer

   Business Layer
Data Layer (IRepository)
       Data Logic
         IRepository
   Repos...
1   Have a runner
1   Have a runner


2   Set the Scene
1   Have a runner


2   Set the Scene


3   Handle your
    Dependencies
Development          Team Work             Process
Object Orientation   Automated Tests      Agile, Lean, XP
      SOLID  ...
http://www.flickr.com/photos/lowfatbrains/80542761/


http://www.flickr.com/photos/jforth/5768064504/


http://www.flickr....
http://www.flickr.com/photos/georgivar/4974112941/


http://www.flickr.com/photos/redbettyblack/395899686/sizes/


http://...
http://www.flickr.com/photos/utslibrary/6776175796/


http://www.flickr.com/photos/yardsale/4524101944/


http://www.flick...
@calebjenkins                  http://developingux.com
    @proactionmentor   caleb@calebjenkins.com
Coding Naked
Coding Naked
Coding Naked
Coding Naked
Coding Naked
Coding Naked
Upcoming SlideShare
Loading in …5
×

of

Coding Naked Slide 1 Coding Naked Slide 2 Coding Naked Slide 3 Coding Naked Slide 4 Coding Naked Slide 5 Coding Naked Slide 6 Coding Naked Slide 7 Coding Naked Slide 8 Coding Naked Slide 9 Coding Naked Slide 10 Coding Naked Slide 11 Coding Naked Slide 12 Coding Naked Slide 13 Coding Naked Slide 14 Coding Naked Slide 15 Coding Naked Slide 16 Coding Naked Slide 17 Coding Naked Slide 18 Coding Naked Slide 19 Coding Naked Slide 20 Coding Naked Slide 21 Coding Naked Slide 22 Coding Naked Slide 23 Coding Naked Slide 24 Coding Naked Slide 25 Coding Naked Slide 26 Coding Naked Slide 27 Coding Naked Slide 28 Coding Naked Slide 29 Coding Naked Slide 30 Coding Naked Slide 31 Coding Naked Slide 32 Coding Naked Slide 33 Coding Naked Slide 34 Coding Naked Slide 35 Coding Naked Slide 36 Coding Naked Slide 37 Coding Naked Slide 38 Coding Naked Slide 39 Coding Naked Slide 40 Coding Naked Slide 41 Coding Naked Slide 42 Coding Naked Slide 43 Coding Naked Slide 44 Coding Naked Slide 45 Coding Naked Slide 46 Coding Naked Slide 47 Coding Naked Slide 48 Coding Naked Slide 49 Coding Naked Slide 50 Coding Naked Slide 51 Coding Naked Slide 52 Coding Naked Slide 53 Coding Naked Slide 54 Coding Naked Slide 55 Coding Naked Slide 56 Coding Naked Slide 57 Coding Naked Slide 58 Coding Naked Slide 59 Coding Naked Slide 60 Coding Naked Slide 61 Coding Naked Slide 62 Coding Naked Slide 63 Coding Naked Slide 64 Coding Naked Slide 65 Coding Naked Slide 66 Coding Naked Slide 67 Coding Naked Slide 68 Coding Naked Slide 69 Coding Naked Slide 70 Coding Naked Slide 71 Coding Naked Slide 72 Coding Naked Slide 73 Coding Naked Slide 74 Coding Naked Slide 75 Coding Naked Slide 76 Coding Naked Slide 77 Coding Naked Slide 78 Coding Naked Slide 79 Coding Naked Slide 80
Upcoming SlideShare
Agile Test Driven Development
Next

4 Likes

Share

Coding Naked

Coding Naked – Practical steps to moving towards & embracing TDD. We'll overview the normal roadblocks that people typically run in to, and practical ways to overcome those road blocks on your way to embracing Test Driven Development - make coding without tests as uncomfortable as coding naked!

Related Books

Free with a 30 day trial from Scribd

See all

Coding Naked

  1. 1. Caleb Jenkins developingUX.com ProactionMentors.com @calebjenkins
  2. 2. I’ll be leaving my clothes on CODING Naked!
  3. 3. Development Engineering Process Object Orientation Automated Tests Agile, Lean, XP SOLID Source Control Team Dynamics Patterns Automated Builds Continuous Learning Secure Coding
  4. 4. Is TDD only for coding elites?
  5. 5. or something for every developer?
  6. 6. How do we make Automated Tests the norm?
  7. 7. make coding without tests as uncomfortable as coding naked
  8. 8. and as fun as playing with Legos
  9. 9. * this is not me
  10. 10. Development …and you build the Legos!
  11. 11. Building Better Legos
  12. 12. Do you write after the fact Tests or design with executable specifications? A test confirms what was done blue prints or specifications define what needs to be done. Automated Unit Tests do both!
  13. 13. What was What should be Discuss: done done Building Inspector vs Architect Designer Which are you? Which do you need? What’s the difference? Unit Tests do both
  14. 14. what are the 4 big parts of unit tests? 16
  15. 15. Code Tests Test Framework Test Runner 17
  16. 16. your application Code what you want to test Tests Test Framework Test Runner 18
  17. 17. your test code the code that tests the Code Tests code that you wrote or are going to write Test Framework Test Runner 19
  18. 18. Code Tests attributes and asserts the framework provides the attributes and asserts Test Framework so we know what the tests Test Runner are doing. Examples: nUnit jUnit cppUnit 20
  19. 19. Code Tests runs the tests often associated with the test framework; is Test Framework Test Runner distinctly separate. sometime integrated in IDE, CI Server or stand alone exe 21
  20. 20. Code Tests Test Framework Test Runner 22
  21. 21. Test Runner Tests Test Framework Tests Code Tests Tests Tests 24
  22. 22. 1 Have a runner
  23. 23. Pick a Test 1 Framework
  24. 24. Test Framework 27
  25. 25. Pick a Test 2 Runner
  26. 26. Test Runners nUnit Test Runner 29
  27. 27. Test Runners nUnit Test Runner Visual Studio (VS Test) 30
  28. 28. Test Runners nUnit Test Runner Visual Studio (VS Test) CodeRush / ReSharper 31
  29. 29. Test Runners nUnit Test Runner Visual Studio (VS Test) CodeRush / ReSharper 32 Continuous Integration (Team City)
  30. 30. Write Test 3 Code
  31. 31. Test Code … 3 A’s Arrange Act Assert Arrange– Set up the scenario and the initial input values. Often in a common [TestFixtureSetup] or [Setup] method Act - Action that creates the outcome that is being tests, usually calling some method in your code to test the result. Assert – Is a boolean statement to your testing framework to declare the expected outcome. Results in Pass or Fail 34
  32. 32. Building better Lego’s UI UI Logic Tests are small App Domain Domain Validation Tests are fast Integration Service Proxy Tests focus on one thing Data Logic Data Access
  33. 33. Simple Tests (return values) with no dependencies… Test Runner Test Code UI Logic App Domain Domain Validation Unit Tests focus on a Unit Test a unit in isolation from other units Control input => Testable output
  34. 34. Demo Let’s write some tests!
  35. 35. 2 Set the Scene context makes all the difference!
  36. 36. Discussion Defining Behavior as a <role>, I will <function> so that <value>
  37. 37. Discussion what if our “tests” given <class> to test when <setup> scenario should <test> outcome matched our language?
  38. 38. Discussion BDD
  39. 39. Resources & Frameworks BDD more than TDD done right http://neelnarayan.blogspot.com/2010/07/bdd-is-more-than-tdd-done-right.html behavior driven, test driven, domain driven http://lucisferre.net/2011/02/05/behavior-driven-test-driven-domain-driven-design/ nBehave, nSpec, SpecFlow, StoryQ, mSpec, StorEvil introducing BDD http://dannorth.net/introducing-bdd/
  40. 40. 3 Handle your dependencies
  41. 41. Dependencies “The single greatest thing that you can do to make your code more testable and healthy is to start taking a Dependency Injection approach to writing software” Real World .NET, C# and Silverlight Caleb Jenkins (Wrox Press 2012)
  42. 42. How do you test this UI UI Logic App Domain Domain Validation Integration Service Proxy Data Logic with these Data Access dependencies
  43. 43. UI UI Logic App Domain Domain Validation Integration Service Proxy Data Logic Data Access
  44. 44. Test Runner Test Code UI Logic App Domain Domain Validation Integration Service Proxy Dependency Injection + Interfaces Faked dependencies to increase unit isolation Leverage mocking frameworks makes life better
  45. 45. Note: Dependency Injection will turn you in to a complete coding Ninja, however the full scope of DI with any of the many DI frameworks is beyond the scope of this talk
  46. 46. http://developingUX.com/DI/
  47. 47. Mocking Framework “A mocking framework allows you to create fake classes on the fly in-line with your test code. That is a bit of a simplification, mocking frameworks use a combination of emits, reflection and generics to create run-time instance implementations of .NET Interfaces – whew, that’s a mouthful - it’s a whole lot easier to say that they create fake classes on the fly!” Real World .NET, C# and Silverlight Caleb Jenkins (Wrox Press 2012)
  48. 48. Mocking in .NET
  49. 49. Bringing DI together
  50. 50. IData mockData = MockRepository.GenerateMock<IData>(); mockData.Expect(x => x.getAll<account>()) .Return(sampleAccounts).Repeat.Once(); IAccountServices accountService = new AcmeAccountService(mockData); var act = accountService.GetAccount(known_account_id); mockData.VerifyAllExpectations();
  51. 51. IData mockData = MockRepository.GenerateMock<IData>(); mockData.Expect(x => x.getAll<account>()) .Return(sampleAccounts).Repeat.Once(); IAccountServices accountService = new AcmeAccountService(mockData); var act = accountService.GetAccount(known_account_id); mockData.VerifyAllExpectations();
  52. 52. IData mockData = MockRepository.GenerateMock<IData>(); mockData.Expect(x => x.getAll<account>()) .Return(sampleAccounts).Repeat.Once(); IAccountServices accountService = new AcmeAccountService(mockData); var act = accountService.GetAccount(known_account_id); mockData.VerifyAllExpectations();
  53. 53. Demo Mocking Confidential
  54. 54. the problem with edges
  55. 55. UI Business Data
  56. 56. Edges are Hard to Test UI Business Data
  57. 57. Testing edges can be like testing to see if you’re good at cliff jumping Confidential
  58. 58. That’s not me Confidential
  59. 59. You’re either an expert and it works… ..or you’re stuff on a rock. Confidential
  60. 60. Edges are Hard to Test UI UI Data Business Data Logic Logic
  61. 61. Edges are still Edges are Hard to Test Data UI Data UI Business Logic Logic by separating UI/Data edges from UI/Data logic we’re increasing the testable area
  62. 62. Edges are still Edges are Hard to Test Data UI Data UI Business Logic Logic we’ve also made it easier to implement by separating UI/Data edges from various UI and Data platforms UI/Data logic we’re increasing the testable area without affecting the application logic
  63. 63. MVC MVP M-V-VM 72
  64. 64. MVC MVP M-V-VM 73
  65. 65. Model View Controller (MVC) • All input is routed to a controller • Example Web Scenarios • ASP.NET MVC Framework Model View Presenter (MVP) • View initiates Presenter • UI Logic is contained in Presenter • Example WinApp & ASP.NET Webform apps Model View ViewModel (MVVM) • ViewModel is a view specific model • VM is can mash up application models • UI logic contained in ViewModel • Example Rich Data binding Scenarios (WPF / Silverlight) 74
  66. 66. Application UI Layer Business Layer Data Layer (IRepository) Data Logic IRepository Repository handles the CRUD and “bare metal” Data Interactions. Consider ADO.NET, nHibernate, EF, LinqToSQL Data Base 76
  67. 67. 1 Have a runner
  68. 68. 1 Have a runner 2 Set the Scene
  69. 69. 1 Have a runner 2 Set the Scene 3 Handle your Dependencies
  70. 70. Development Team Work Process Object Orientation Automated Tests Agile, Lean, XP SOLID Source Control Team Dynamics Patterns Automated Builds Continuous Learning Secure Coding
  71. 71. http://www.flickr.com/photos/lowfatbrains/80542761/ http://www.flickr.com/photos/jforth/5768064504/ http://www.flickr.com/photos/laughingsquid/255915238/ http://www.flickr.com/photos/dieselbug2007/370557683/
  72. 72. http://www.flickr.com/photos/georgivar/4974112941/ http://www.flickr.com/photos/redbettyblack/395899686/sizes/ http://www.flickr.com/photos/goldberg/815408116/ http://www.flickr.com/photos/fudj/122371431/
  73. 73. http://www.flickr.com/photos/utslibrary/6776175796/ http://www.flickr.com/photos/yardsale/4524101944/ http://www.flickr.com/photos/38738277@N04/3652658961/ http://www.flickr.com/photos/m0php/530526644/
  74. 74. @calebjenkins http://developingux.com @proactionmentor caleb@calebjenkins.com
  • GregPitcher

    May. 12, 2019
  • calebjenkins

    Jul. 24, 2014
  • JonathanBradshaw

    May. 7, 2013
  • larabecker

    May. 11, 2012

Coding Naked – Practical steps to moving towards & embracing TDD. We'll overview the normal roadblocks that people typically run in to, and practical ways to overcome those road blocks on your way to embracing Test Driven Development - make coding without tests as uncomfortable as coding naked!

Views

Total views

4,209

On Slideshare

0

From embeds

0

Number of embeds

135

Actions

Downloads

1

Shares

0

Comments

0

Likes

4

×