Presentation is loading. Please wait.

Presentation is loading. Please wait.

A Second Look at Unit Senior Developer, Bouvet

Similar presentations


Presentation on theme: "A Second Look at Unit Senior Developer, Bouvet"— Presentation transcript:

1 A Second Look at Unit Testing @RoyOsherove Senior Developer, Bouvet roy@osherove.com

2

3 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

4

5

6 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

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

8

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

10

11 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.

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

13 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

14

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

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

17 Setup Methods

18 Isolation Frameworks  Constrained vs.  Unconstrained

19

20 Recursive Fakes & Chained Expectations  Recursive is not explicit:  Person.Manager.Manager is already a fake instance without asking for it  Chained Expectations are explicit  Mock.Arrange(() => Person.Manager.Manager).Returns(fakeManager)

21 Team Agile - All rights reserved

22 Unconstrained

23 Constrained

24 Goodbye RhinoMocks  Hello FakeItEasy, NSubstitute

25 Values of a Good Isolation Framework  Simple  Single point of entry  Easy to remember  Intellisense Guidance  Test Robustness  Recursive Fakes  non strict by default  Helpful  Helpful Error Messages  No surprises Team Agile - All rights reserved

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

27

28

29

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

31 Cross Cutting Fakes

32 Old code

33 Fake New code

34

35 Impacting Change

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

37 Another book?

38 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

39

40 Build and Delivery

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

42

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

44 Build Patterns

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

46 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

47 Fill In The Blanks

48 Location Agnostic

49 Extract Script

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

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

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

53 How Fast?

54 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

55 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

56 Thank you! royo@bouvet.noroy@osherove.com@RoyOsherove


Download ppt "A Second Look at Unit Senior Developer, Bouvet"

Similar presentations


Ads by Google