Presentation is loading. Please wait.

Presentation is loading. Please wait.

A Second Look at Unit Testing

Similar presentations


Presentation on theme: "A Second Look at Unit Testing"— Presentation transcript:

1 A Second Look at Unit Testing

2 Unit Of Work Setup Methods Constrained vs. Unconstrained Isolation Frameworks Principles of Good Isolation Frameworks Faking Deep Legacy is OK Six Influence Forces Beautiful Builds

3

4 Bottleneck Ninja Test Review Lion Build Bear

5 Unit Of Work Production Code Unit Of Work Production Code Unit Of Work Return Value/Exceptio n Noticeable State Change 3 rd Party call Public API Test

6 Production Code Unit Of Work Production Code Unit Of Work Return Value/Exceptio n Public API Assert Test

7 Production Code Unit Of Work Production Code Unit Of Work Noticeable State Change Test Public API Assert

8 Production Code Unit Of Work Production Code Unit Of Work 3 rd Party call Test Public API Assert 3 rd Party Unit Of Work

9 Production Code Unit Of Work Production Code Unit Of Work 3 rd Party call Test Public API Assert 3 rd Party Unit Of Work Mock

10 Noticeable System Behavior Change  Noticeable by a user of the public API,  at the same level of the entry point that made the change.  ACT and ASSERT on the same level of APIs.

11 Naming by Unit Of Work  UnitOfWork_Input_Expecte dOutput  UnitOfWork_LogicalAction_ ExpectedChangeInBehavior  UnitOfWork_ActionOrInput_ ExepectedCallToThirdParty

12 Naming by Unit Of Work  Addition_PositiveNumbers_ ReturnsSum()  Addition_WhenCalled_Reset sTheNextSum()  Addition_NegativeNumbers_ CallsLogger()

13 Setup Methods

14 Isolation Frameworks  Constrained vs.  Unconstrained

15

16 Goodbye RhinoMocks  Hello FakeItEasy, NSubstitute

17 Isolation frameworks Futures  Usability  Readability  Good Errors  Simplicity  Robust future proof tests  Less over specification  Non strict  Recursive Fakes

18

19 Rspec style is ok Assert multiple results on same unit of work

20

21

22

23 LEGACY CODE Faking Deep System Internals is OK Example - SilverUnit

24 Cross Cutting Fakes

25 Old code

26 Fake New code

27

28 Impacting Change

29 6 influence forces  Personal Ability Motivation Motivation  Social Ability Motivation Motivation  Environmental Ability Motivation Motivation

30 Another book?

31 Tools  Pex – yes  Moles (ms fakes) – NO  JustMock - Maybe  Nuget – YES  Chocolatey – YES  TeamCity – YES  FinalBuilder – YES  Ruby and Rake – Maybe  Amazon AWS agent hosting – YES  Git for very small commits - YES

32

33 Build and Delivery

34 Hardware  Build Machine (with teamcity)  + agent machines (optional)  Test Machine  Staging Machine  Production Machine  This can all be in the cloud (EC2 is wonderful)

35

36 Build Configurations  Continuous Integration Build  Slow Build (nightly, optional)  Deploy to test servers  Deploy to staging servers (optional)  Deploy to production

37 Build Patterns

38 Build Script Injection  Allow version aware builds  Build scripts are part of source control  Build configurations on the CI server are dumb triggers

39 Fill In The Blanks  Build Script uses placeholders for system related knowledge  Placeholders are filled from environment variables or other types of parameters to the command line  These variables are SET by the Build Configuration on the CI server

40 Fill In The Blanks

41 Location Agnostic

42 Extract Script

43 Build Chain Triggers Triggered by checkin Triggered by end of previous Manual Build Chaining

44 Slow Builds Do X Do X + Y Do X + Y + Z Do X + y + Z + N

45 Cumulative, Fast Builds Do X Do Y Do Z Do N

46 How Fast?

47 Shipping Skeleton  Start by releasing  Deploy a hello world empty skeleton  Then fill out the product  Continue adding small build features as you go along

48  Extract Script  Shipping Skeleton  Fill in the blanks  Cumulative Builds  Build Waves  Location Agnostic BeautifulBuilds.com

49  (wtf how many books?)

50 Courses I’m Doing  Beautiful builds  TDD with JS  TDD with Ruby  Art of Unit Testing in.NET from scratch   Norway & Sweden  Osherove.com for info

51 A short song?

52 This is a test line

53 It looks like you’re doing just fine

54 It’s time for a song of mine

55 It’s late in the evening

56  I’m wondering what words to say  It’s so hard to breath here  The customer’s face is gray

57 And then he asks me Is the product alright?

58 And I say “yes, we deploy it all tonight”

59 I check in the changes

60 The code doesn’t even compile I wish I was home now Instead I fake a big smile

61 And when they ask me Is the code alright?

62 I say “yes, it seems to compile tonight’

63 I feel horrible Because I see The sadness in their eyes

64 When they find out That the product Doesn’t even have log files This thing is doomed

65 It’s time to go home now And I’ve got an aching head So I lock my computer And pray that tomorrow I’m dead

66 When my wife asks me “Do you feel alright?”

67  I say  “yes. Let’s watch game of thrones tonight”

68 I feel miserable  Because I’ll guess  The madness in their talk

69  When they find out  that tomorrow  I don’t plan to come to work  And write my CV

70 Thank you!  Beautiful builds  TDD with JS  TDD with Ruby  Art of Unit Testing in.NET from scratch   Norway & Sweden


Download ppt "A Second Look at Unit Testing"

Similar presentations


Ads by Google