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 JenkinsdevelopingUX.comProactionMentors.com   @calebjenkins
I’ll be                leaving                my                clothes                onCODING Naked!
Development           Engineering          Process Object Orientation    Automated Tests     Agile, Lean, XP       SOLID  ...
Is TDDonly for coding elites?
or something forevery developer?
How do we make Automated          Tests the norm?
make coding without                tests asuncomfortable 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 Testsor design with executablespecifications?A test confirms what was doneblue prints or speci...
What was  Whatshould be            Discuss:                  done  done            Building Inspector                    v...
what are the 4 big parts of unit tests?16
Code            Tests     Test Framework   Test Runner17
your application           Code     what you want to test                                Tests     Test Framework         ...
your test code                        the code that tests the         Code                   Tests                      co...
Code                   Tests     attributes and asserts      the framework provides     the attributes and asserts       T...
Code                 Tests                          runs the tests                      often associated with the         ...
Code            Tests     Test Framework   Test Runner22
Test Runner            Tests                             Test Framework            Tests     Code            Tests        ...
1   Have a runner
Pick a Test1   Framework
Test Framework27
Pick a Test2   Runner
Test Runners     nUnit Test Runner29
Test Runners     nUnit Test Runner     Visual Studio (VS Test)30
Test Runners     nUnit Test Runner     Visual Studio (VS Test)          CodeRush / ReSharper31
Test Runners     nUnit Test Runner     Visual Studio (VS Test)         CodeRush / ReSharper32      Continuous Integration ...
Write Test3   Code
Test Code … 3 A’s Arrange                       Act                      AssertArrange– Set up the scenario and the initia...
Building better Lego’s    UI           UI Logic                           Tests are smallApp Domain      Domain Validation...
Simple Tests (return values)               with no dependencies…                             Test Runner                  ...
DemoLet’s writesome tests!
2         Set the Scenecontext makes all the difference!
DiscussionDefining Behavior   as a <role>, I will <function> so that <value>
Discussionwhat if our “tests” given <class> to testwhen <setup> scenarioshould <test> outcome     matched our      language?
Discussion    BDD
Resources & Frameworks                                                                BDD     more than TDD done right   h...
3   Handle your    dependencies
Dependencies“The single greatest thing that you can doto make your code more testable andhealthy is to start taking a Depe...
How do you test this    UI           UI LogicApp Domain      Domain Validation         Integration      Service Proxy     ...
UI           UI LogicApp Domain      Domain Validation         Integration      Service Proxy                  Data Logic ...
Test Runner                         Test Code     UI LogicApp Domain      Domain Validation     Integration         Servic...
Note:Dependency Injection  will turn you in to a complete  coding Ninja, however the  full scope of DI with any of  the ma...
http://developingUX.com/DI/
Mocking Framework“A mocking framework allows you to create fake classes onthe fly in-line with your test code. That is a b...
Mocking in .NET
Bringing DI together
IData mockData = MockRepository.GenerateMock<IData>();mockData.Expect(x => x.getAll<account>())           .Return(sampleAc...
IData mockData = MockRepository.GenerateMock<IData>();mockData.Expect(x => x.getAll<account>())           .Return(sampleAc...
IData mockData = MockRepository.GenerateMock<IData>();mockData.Expect(x => x.getAll<account>())           .Return(sampleAc...
DemoMocking          Confidential
the problem with edges
UI   Business   Data
Edges are      Hard to TestUI   Business        Data
Testing edgescan be liketesting to see ifyou’re good atcliff jumping                    Confidential
That’s not me       Confidential
You’re either anexpert and it works…     ..or you’re     stuff on a rock.                 Confidential
Edges are      Hard to TestUI    UI Data     Business        Data     Logic         Logic
Edges are still                  Edges are                  Hard to Test                                          Data    ...
Edges are still                  Edges are                  Hard to Test                                          Data    ...
MVC MVPM-V-VM         72
MVC MVPM-V-VM         73
Model View Controller (MVC)• All input is routed to a controller• Example Web Scenarios• ASP.NET MVC Framework Model View ...
Application          UI Layer   Business LayerData Layer (IRepository)       Data Logic         IRepository   Repository h...
1   Have a runner
1   Have a runner2   Set the Scene
1   Have a runner2   Set the Scene3   Handle your    Dependencies
Development          Team Work             ProcessObject Orientation   Automated Tests      Agile, Lean, XP      SOLID    ...
http://www.flickr.com/photos/lowfatbrains/80542761/http://www.flickr.com/photos/jforth/5768064504/http://www.flickr.com/ph...
http://www.flickr.com/photos/georgivar/4974112941/http://www.flickr.com/photos/redbettyblack/395899686/sizes/http://www.fl...
http://www.flickr.com/photos/utslibrary/6776175796/http://www.flickr.com/photos/yardsale/4524101944/http://www.flickr.com/...
@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
×

Coding Naked

3,632 views

Published on

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!

Published in: Technology, Education
  • Be the first to comment

Coding Naked

  1. 1. Caleb JenkinsdevelopingUX.comProactionMentors.com @calebjenkins
  2. 2. I’ll be leaving my clothes onCODING 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 TDDonly for coding elites?
  5. 5. or something forevery developer?
  6. 6. How do we make Automated Tests the norm?
  7. 7. make coding without tests asuncomfortable 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 Testsor design with executablespecifications?A test confirms what was doneblue prints or specificationsdefine what needs to be done.Automated Unit Tests do both!
  13. 13. What was Whatshould 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 Runner17
  16. 16. your application Code what you want to test Tests Test Framework Test Runner18
  17. 17. your test code the code that tests the Code Tests code that you wrote or are going to write Test Framework Test Runner19
  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 cppUnit20
  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 exe21
  20. 20. Code Tests Test Framework Test Runner22
  21. 21. Test Runner Tests Test Framework Tests Code Tests Tests Tests24
  22. 22. 1 Have a runner
  23. 23. Pick a Test1 Framework
  24. 24. Test Framework27
  25. 25. Pick a Test2 Runner
  26. 26. Test Runners nUnit Test Runner29
  27. 27. Test Runners nUnit Test Runner Visual Studio (VS Test)30
  28. 28. Test Runners nUnit Test Runner Visual Studio (VS Test) CodeRush / ReSharper31
  29. 29. Test Runners nUnit Test Runner Visual Studio (VS Test) CodeRush / ReSharper32 Continuous Integration (Team City)
  30. 30. Write Test3 Code
  31. 31. Test Code … 3 A’s Arrange Act AssertArrange– Set up the scenario and the initial input values.Often in a common [TestFixtureSetup] or [Setup] methodAct - Action that creates the outcome that is being tests, usuallycalling some method in your code to test the result.Assert – Is a boolean statement to your testing framework todeclare the expected outcome. Results in Pass or Fail 34
  32. 32. Building better Lego’s UI UI Logic Tests are smallApp 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. DemoLet’s writesome tests!
  35. 35. 2 Set the Scenecontext makes all the difference!
  36. 36. DiscussionDefining Behavior as a <role>, I will <function> so that <value>
  37. 37. Discussionwhat if our “tests” given <class> to testwhen <setup> scenarioshould <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.htmlbehavior 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 doto make your code more testable andhealthy is to start taking a DependencyInjection approach to writing software” Real World .NET, C# and Silverlight Caleb Jenkins (Wrox Press 2012)
  42. 42. How do you test this UI UI LogicApp Domain Domain Validation Integration Service Proxy Data Logic with these Data Access dependencies
  43. 43. UI UI LogicApp Domain Domain Validation Integration Service Proxy Data Logic Data Access
  44. 44. Test Runner Test Code UI LogicApp 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 onthe fly in-line with your test code. That is a bit of asimplification, mocking frameworks use a combination ofemits, reflection and generics to create run-time instanceimplementations of .NET Interfaces – whew, that’s a mouthful- it’s a whole lot easier to say that they create fake classes onthe 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. DemoMocking Confidential
  54. 54. the problem with edges
  55. 55. UI Business Data
  56. 56. Edges are Hard to TestUI Business Data
  57. 57. Testing edgescan be liketesting to see ifyou’re good atcliff jumping Confidential
  58. 58. That’s not me Confidential
  59. 59. You’re either anexpert and it works… ..or you’re stuff on a rock. Confidential
  60. 60. Edges are Hard to TestUI UI Data Business Data Logic Logic
  61. 61. Edges are still Edges are Hard to Test Data UI DataUI Business Logic Logic by separating UI/Data edges fromUI/Data logic we’re increasing the testable area
  62. 62. Edges are still Edges are Hard to Test Data UI DataUI Business Logic Logic we’ve also made it easier to implement by separating UI/Data edges from various UI and Data platformsUI/Data logic we’re increasing the testable area without affecting the application logic
  63. 63. MVC MVPM-V-VM 72
  64. 64. MVC MVPM-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 LayerData 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 runner2 Set the Scene
  69. 69. 1 Have a runner2 Set the Scene3 Handle your Dependencies
  70. 70. Development Team Work ProcessObject 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

×