Slide 1

Slide 1 text

16 – 17 November, Sofia ISTACON.ORG How to Tame TDD By Vladik Khononov

Slide 2

Slide 2 text

16 – 17 November, Sofia ISTACON.ORG My twitter is I blog Chief Architect My email is vladik
 @ vladikk @ vladikk.com @ Naxex @ khononov.com


Slide 3

Slide 3 text

16 – 17 November, Sofia ISTACON.ORG

Slide 4

Slide 4 text

16 – 17 November, Sofia ISTACON.ORG Agenda TDD Journey Fix #1: Scoping Unit Tests Fix #2: Testing Strategies Common misconceptions Fix #3: TDD & Design TDD Revisited Cyclomatic Complexity Business Logic Modeling Patterns

Slide 5

Slide 5 text

16 – 17 November, Sofia ISTACON.ORG

Slide 6

Slide 6 text

16 – 17 November, Sofia ISTACON.ORG

Slide 7

Slide 7 text

16 – 17 November, Sofia ISTACON.ORG • TDD?

Slide 8

Slide 8 text

16 – 17 November, Sofia ISTACON.ORG • TDD? • Done TDD?

Slide 9

Slide 9 text

16 – 17 November, Sofia ISTACON.ORG • TDD? • Done TDD? • Still doing TDD?

Slide 10

Slide 10 text

16 – 17 November, Sofia ISTACON.ORG Our TDD Journey

Slide 11

Slide 11 text

16 – 17 November, Sofia ISTACON.ORG TDD

Slide 12

Slide 12 text

16 – 17 November, Sofia ISTACON.ORG

Slide 13

Slide 13 text

16 – 17 November, Sofia ISTACON.ORG v1

Slide 14

Slide 14 text

16 – 17 November, Sofia ISTACON.ORG v1

Slide 15

Slide 15 text

16 – 17 November, Sofia ISTACON.ORG v1

Slide 16

Slide 16 text

16 – 17 November, Sofia ISTACON.ORG v1 v2 UNIT
 TESTS

Slide 17

Slide 17 text

16 – 17 November, Sofia ISTACON.ORG

Slide 18

Slide 18 text

16 – 17 November, Sofia ISTACON.ORG

Slide 19

Slide 19 text

16 – 17 November, Sofia ISTACON.ORG

Slide 20

Slide 20 text

16 – 17 November, Sofia ISTACON.ORG v1 v2 UNIT
 TESTS

Slide 21

Slide 21 text

16 – 17 November, Sofia ISTACON.ORG v1 v2 UNIT
 TESTS

Slide 22

Slide 22 text

16 – 17 November, Sofia ISTACON.ORG v1 v2 v5 OH SHIT!

Slide 23

Slide 23 text

16 – 17 November, Sofia ISTACON.ORG v1 v2 v5 OH SHIT!

Slide 24

Slide 24 text

16 – 17 November, Sofia ISTACON.ORG v1 v2 v5 OH SHIT!

Slide 25

Slide 25 text

16 – 17 November, Sofia ISTACON.ORG Test Code

Slide 26

Slide 26 text

16 – 17 November, Sofia ISTACON.ORG Fixing failed tests Test Code

Slide 27

Slide 27 text

16 – 17 November, Sofia ISTACON.ORG v1 v2 v5 OH SHIT!

Slide 28

Slide 28 text

16 – 17 November, Sofia ISTACON.ORG v5 v1 v2 OH SHIT!

Slide 29

Slide 29 text

16 – 17 November, Sofia ISTACON.ORG v5 v1 v2

Slide 30

Slide 30 text

16 – 17 November, Sofia ISTACON.ORG • Write a failing Unit Test

Slide 31

Slide 31 text

16 – 17 November, Sofia ISTACON.ORG • Write a failing Unit Test • Write code to a make it pass • Proper design • Isolate the Class under test

Slide 32

Slide 32 text

16 – 17 November, Sofia ISTACON.ORG • Write a failing Unit Test • Write code to a make it pass • Proper design • Isolate the Class under test Fakes Mocks Stubs

Slide 33

Slide 33 text

16 – 17 November, Sofia ISTACON.ORG • Write a failing Unit Test • Write code to a make it pass • Proper design • Isolate the Class under test • Refactor Fakes Mocks Stubs

Slide 34

Slide 34 text

16 – 17 November, Sofia ISTACON.ORG • Write a failing Unit Test • Write code to a make it pass • Proper design • Isolate the Class under test • Refactor Fakes Mocks Stubs

Slide 35

Slide 35 text

16 – 17 November, Sofia ISTACON.ORG • Write a failing Unit Test • Write code to a make it pass • Proper design • Isolate the Class under test • Refactor • Repeat • 100% unit test coverage • Maintainable and extendable code • FAST!!! Fakes Mocks Stubs

Slide 36

Slide 36 text

16 – 17 November, Sofia ISTACON.ORG • Write a failing Unit Test • Write code to a make it pass • Proper design • Isolate the Class under test • Refactor • Repeat • 100% unit test coverage • Maintainable and extendable code • FAST!!! Fakes Mocks Stubs

Slide 37

Slide 37 text

16 – 17 November, Sofia ISTACON.ORG • Write a failing Unit Test • Write code to a make it pass • Proper design • Isolate the Class under test • Refactor • Repeat • 100% unit test coverage • Maintainable and extendable code • FAST!!! Fakes Mocks Stubs

Slide 38

Slide 38 text

16 – 17 November, Sofia ISTACON.ORG • Write a failing Unit Test • Write code to a make it pass • Proper design • Isolate the Class under test • Refactor • Repeat • 100% unit test coverage • Maintainable and extendable code • FAST!!! Fakes Mocks Stubs TEST-DRIVEN DESIGN

Slide 39

Slide 39 text

16 – 17 November, Sofia ISTACON.ORG Fakes Mocks Stubs • Write a failing Unit Test • Write code to a make it pass • Proper design • Isolate the Class under test • Refactor • Repeat • 100% unit test coverage • Maintainable and extendable code • FAST!!! TEST-DRIVEN DESIGN

Slide 40

Slide 40 text

16 – 17 November, Sofia ISTACON.ORG Fakes Mocks Stubs • Write a failing Unit Test • Write code to a make it pass • Proper design • Isolate the Class under test • Refactor • Repeat • 100% unit test coverage • Maintainable and extendable code • FAST!!! TEST-DRIVEN DESIGN

Slide 41

Slide 41 text

16 – 17 November, Sofia ISTACON.ORG Fakes Mocks Stubs • Write a failing Unit Test • Write code to a make it pass • Proper design • Isolate the Class under test • Refactor • Repeat • 100% unit test coverage • Maintainable and extendable code • FAST!!! TEST-DRIVEN DESIGN

Slide 42

Slide 42 text

16 – 17 November, Sofia ISTACON.ORG What is a Unit?

Slide 43

Slide 43 text

16 – 17 November, Sofia ISTACON.ORG CLASS?

Slide 44

Slide 44 text

16 – 17 November, Sofia ISTACON.ORG

Slide 45

Slide 45 text

16 – 17 November, Sofia ISTACON.ORG •OOP Only CLASS?

Slide 46

Slide 46 text

16 – 17 November, Sofia ISTACON.ORG •OOP Only •Fragile CLASS?

Slide 47

Slide 47 text

16 – 17 November, Sofia ISTACON.ORG Unit

Slide 48

Slide 48 text

16 – 17 November, Sofia ISTACON.ORG Mock Stub Mock Stub Stub Stub Unit

Slide 49

Slide 49 text

16 – 17 November, Sofia ISTACON.ORG

Slide 50

Slide 50 text

16 – 17 November, Sofia ISTACON.ORG

Slide 51

Slide 51 text

16 – 17 November, Sofia ISTACON.ORG

Slide 52

Slide 52 text

16 – 17 November, Sofia ISTACON.ORG •OOP Only •Fragile •No! CLASS?

Slide 53

Slide 53 text

16 – 17 November, Sofia ISTACON.ORG ” “ A unit is a single logical functional use case in the system that can be invoked by some
 public interface… A unit can span a single method, a whole class or multiple classes working together to achieve one single logical purpose Roy Osherove The Art of Unit Testing

Slide 54

Slide 54 text

16 – 17 November, Sofia ISTACON.ORG

Slide 55

Slide 55 text

16 – 17 November, Sofia ISTACON.ORG List Task Status * 1

Slide 56

Slide 56 text

16 – 17 November, Sofia ISTACON.ORG Task List Status Units

Slide 57

Slide 57 text

16 – 17 November, Sofia ISTACON.ORG Task List Status Units

Slide 58

Slide 58 text

16 – 17 November, Sofia ISTACON.ORG Create a new list Create a new task Mark as completed Update list name Units

Slide 59

Slide 59 text

16 – 17 November, Sofia ISTACON.ORG Unit Test: Create a new task List Task Status

Slide 60

Slide 60 text

16 – 17 November, Sofia ISTACON.ORG Unit Test: Create a new task List Task Status Database Online Calendar Isolate External systems

Slide 61

Slide 61 text

16 – 17 November, Sofia ISTACON.ORG • Align Units with the system’s use cases • Do not isolate implementation details • Isolate external systems and services Adjustment #1

Slide 62

Slide 62 text

16 – 17 November, Sofia ISTACON.ORG Why Unit Tests?

Slide 63

Slide 63 text

16 – 17 November, Sofia ISTACON.ORG Unit Tests Integration Tests End to End Tests

Slide 64

Slide 64 text

16 – 17 November, Sofia ISTACON.ORG Number of tests * Execution time = Feedback time

Slide 65

Slide 65 text

16 – 17 November, Sofia ISTACON.ORG

Slide 66

Slide 66 text

16 – 17 November, Sofia ISTACON.ORG

Slide 67

Slide 67 text

16 – 17 November, Sofia ISTACON.ORG * Execution time = Feedback time Number of tests

Slide 68

Slide 68 text

16 – 17 November, Sofia ISTACON.ORG * Execution time = Feedback time Number of tests

Slide 69

Slide 69 text

16 – 17 November, Sofia ISTACON.ORG public User(long id, Agency agency, User createdBy, DateTime createdOn) : base(createdBy, createdOn) { this.Id = id; this.agency = agency; this.AutoLeadAssignmentPausedUntil = DateTime.UtcNow; } public User(Agency agency, User createdBy, DateTime createdOn) : base(createdBy, createdOn) { this.agency = agency; this.AutoLeadAssignmentPausedUntil = DateTime.UtcNow; } public virtual void AddGroup(Group group) { RemoveGroupsWithOtherDesks(group.Desk); groups.AddIfNotExists(group); if (!group.Users.Contains(this)) group.AddUser(this, false); } public virtual void SetActive(bool value) { if (value && !this.Active) this.StatisticsShouldBeRecalculated = true; this.Active = value; } private void RemoveGroupsWithOtherDesks(Desk newDesk) { if (newDesk == Desk) return; foreach (var g in groups) g.RemoveUser(this); groups.Clear(); } public virtual void AddOrganizationUnit(OrganizationUnitUserAssociation ouUserAssociation) { if (organizationUnitsAssociations.All(x => x.Unit.Id != ouUserAssociation.Unit.Id)) organizationUnitsAssociations.Add(ouUserAssociation); } public virtual Desk[] GetManagedDesks(Advertiser advertiser) { return this.CanAccessAllDesks ? advertiser.Desks.ToArray() : this.ManagesDesks.ToArray(); } public virtual Group[] GetManagedGroups(Advertiser advertiser) { return this.CanAccessAllDesks ? advertiser.Desks.SelectMany(x => x.Groups).Distinct().ToArray() : GetManagedDesks(advertiser) .SelectMany(x => x.Groups) .Concat(this.Groups.Where(x => x.IsManagedBy(this))) .Distinct() .ToArray(); } public virtual Advertiser[] GetAllowedAdvertisers()

Slide 70

Slide 70 text

16 – 17 November, Sofia ISTACON.ORG Number of independent execution paths within a section of code Cyclomatic Complexity

Slide 71

Slide 71 text

16 – 17 November, Sofia ISTACON.ORG DoSomething DoSomethingElse ExecuteSomething ExecuteSomethingElse Low C. Complexity

Slide 72

Slide 72 text

16 – 17 November, Sofia ISTACON.ORG if(SomeCondition()) DoSomething(); else DoSomethingElse(); if(AnotherCondition()) ExecuteSomething(); else ExecuteSomethingElse(); High C. Complexity

Slide 73

Slide 73 text

16 – 17 November, Sofia ISTACON.ORG Cyclomatic
 Complexity Amount
 of Tests

Slide 74

Slide 74 text

16 – 17 November, Sofia ISTACON.ORG M = E − N + 2P M = E − N + 2 M = π − s + 2

Slide 75

Slide 75 text

16 – 17 November, Sofia ISTACON.ORG

Slide 76

Slide 76 text

16 – 17 November, Sofia ISTACON.ORG Cyclomatic
 Complexity Amount
 of Tests

Slide 77

Slide 77 text

16 – 17 November, Sofia ISTACON.ORG Business Logic Modeling Patterns

Slide 78

Slide 78 text

16 – 17 November, Sofia ISTACON.ORG Transaction Script Active Record Domain Model Business Logic Modeling Patterns

Slide 79

Slide 79 text

16 – 17 November, Sofia ISTACON.ORG Simple logic Extract, Transform and Load Procedural code Transaction Script

Slide 80

Slide 80 text

16 – 17 November, Sofia ISTACON.ORG JSON XML JSON2XML

Slide 81

Slide 81 text

16 – 17 November, Sofia ISTACON.ORG Source Database IMPORT

Slide 82

Slide 82 text

16 – 17 November, Sofia ISTACON.ORG DB.StartTransaction(); var job = DB.LoadNextJob();
 var json = LoadFile(source); var xml = ConvertJsonToXml(json); WriteFile(destionation, xml.ToString(); DB.MarkJobAsCompleted(job); DB.Commit()

Slide 83

Slide 83 text

16 – 17 November, Sofia ISTACON.ORG Simple logic ETL-Like processes Procedural code Transaction Script

Slide 84

Slide 84 text

16 – 17 November, Sofia ISTACON.ORG Unit INTEGRATION END2END

Slide 85

Slide 85 text

16 – 17 November, Sofia ISTACON.ORG Complex data structures Simple logic CRUD Active Record

Slide 86

Slide 86 text

16 – 17 November, Sofia ISTACON.ORG Advertiser Ad Campaign Placement * 1 * Location Website Creatives *

Slide 87

Slide 87 text

16 – 17 November, Sofia ISTACON.ORG Complex data structures Simple logic CRUD Active Record

Slide 88

Slide 88 text

16 – 17 November, Sofia ISTACON.ORG

Slide 89

Slide 89 text

16 – 17 November, Sofia ISTACON.ORG Active Record Presentation Layer Active Records Service / Application Layer Data Structures Business Logic

Slide 90

Slide 90 text

16 – 17 November, Sofia ISTACON.ORG public class User { public Guid Id { get; set; }
 public string Name { get; set; }
 public List Interests { get; set; }
 public Address Address { get; set; } public void Save() { … }
 public void Delete() { … }
 public static User Get(Guid id) { … }
 public static List GetAll() { … } }

Slide 91

Slide 91 text

16 – 17 November, Sofia ISTACON.ORG Active Record Presentation Layer Service / Application Layer Active Records Data Structures Business Logic

Slide 92

Slide 92 text

16 – 17 November, Sofia ISTACON.ORG public class CreateUser { public void Execute(userDetails) { try { DB.StartTransaction();
 var user = new User();
 user.Name = userDetails.Name;
 user.Email = userDetails.Email;
 user.Save();
 DB.Commit(); } catch { DB.Rollback();
 throw; } } }

Slide 93

Slide 93 text

16 – 17 November, Sofia ISTACON.ORG public class User { public Guid Id { get; set; }
 public string Name { get; set; }
 public List Interests { get; set; }
 public Address Address { get; set; } public void Save() { … }
 public void Delete() { … }
 public static User Get(Guid id) { … }
 public static List GetAll() { … } }

Slide 94

Slide 94 text

16 – 17 November, Sofia ISTACON.ORG public class CreateUser { public void Execute(userDetails) { try { DB.StartTransaction();
 var user = new User();
 user.Name = userDetails.Name;
 user.Email = userDetails.Email;
 user.Save();
 DB.Commit(); } catch { DB.Rollback();
 throw; } } }

Slide 95

Slide 95 text

16 – 17 November, Sofia ISTACON.ORG INTEGRATION E2E UNIT

Slide 96

Slide 96 text

16 – 17 November, Sofia ISTACON.ORG Complex logic Business rules Protecting invariants Domain Model

Slide 97

Slide 97 text

16 – 17 November, Sofia ISTACON.ORG public class User { public Guid Id { get; private set; }
 public string Name { get; private set; }
 public List Interests { get; private set; }
 public Address Address { get; private set; } public void UpdateDetails() { … }
 public void AddInterest() { … }
 public static User InitializeNew() { … } }

Slide 98

Slide 98 text

16 – 17 November, Sofia ISTACON.ORG E2E INTEGRATION UNIT

Slide 99

Slide 99 text

16 – 17 November, Sofia ISTACON.ORG Adjustment #2: Testing Strategies

Slide 100

Slide 100 text

16 – 17 November, Sofia ISTACON.ORG • Transaction Script - 100% End to end Adjustment #2: Testing Strategies

Slide 101

Slide 101 text

16 – 17 November, Sofia ISTACON.ORG • Transaction Script - 100% End to end • Active Record - 100% Integration tests Adjustment #2: Testing Strategies

Slide 102

Slide 102 text

16 – 17 November, Sofia ISTACON.ORG • Transaction Script - 100% End to end • Active Record - 100% Integration tests • Domain Model - 100% Unit tests Adjustment #2: Testing Strategies

Slide 103

Slide 103 text

16 – 17 November, Sofia ISTACON.ORG Design?

Slide 104

Slide 104 text

16 – 17 November, Sofia ISTACON.ORG Well designed code is testable

Slide 105

Slide 105 text

16 – 17 November, Sofia ISTACON.ORG Well designed code is testable Testable code is well designed

Slide 106

Slide 106 text

16 – 17 November, Sofia ISTACON.ORG Well designed code is testable Testable code is well designed

Slide 107

Slide 107 text

16 – 17 November, Sofia ISTACON.ORG Transaction Script Active Record Domain Model Business Logic Modeling Patterns

Slide 108

Slide 108 text

16 – 17 November, Sofia ISTACON.ORG • System’s design is driven by its business domain, its needs and its problems • Development can be driven by tests Adjustment #3: Design vs. Development

Slide 109

Slide 109 text

16 – 17 November, Sofia ISTACON.ORG • System’s design is driven by its business domain, its needs and its problems • Development can be driven by tests • Test-Driven Design • Test-Driven Development Adjustment #3: Design vs. Development

Slide 110

Slide 110 text

16 – 17 November, Sofia ISTACON.ORG Taking Care of Tests

Slide 111

Slide 111 text

16 – 17 November, Sofia ISTACON.ORG

Slide 112

Slide 112 text

16 – 17 November, Sofia ISTACON.ORG AUTOMATED TESTS ARE PRODUCTION CODE

Slide 113

Slide 113 text

16 – 17 November, Sofia ISTACON.ORG [TestMethod] public void SetAsUnqualified_ClearWeights() { var lead = BuildLead(10, 15, 24, false); lead.SetAsUnqualified(updatedContactDetails, policy, 12); Assert.AreEqual(12, lead.Proprity); }

Slide 114

Slide 114 text

16 – 17 November, Sofia ISTACON.ORG [TestMethod] public void SetAsUnqualified_ClearWeights() { var lead = BuildLead(10, 15, 24, false); lead.SetAsUnqualified(updatedContactDetails, policy, 12); Assert.AreEqual(12, lead.Proprity); }

Slide 115

Slide 115 text

16 – 17 November, Sofia ISTACON.ORG [TestMethod] public void SetAsUnqualified_ClearWeights() { var lead = BuildLead(someUserId, groupId, events, notNew); lead.SetAsUnqualified(updatedContactDetails, policy, agentId); Assert.AreEqual(newLeadPriority, lead.Proprity); }

Slide 116

Slide 116 text

16 – 17 November, Sofia ISTACON.ORG [TestMethod] public void CreateLeadActivity_CreateValidJSON() { var depositActivity = new DepositActivity(); depositActivity.ActivityTypeId = 6002; depositActivity.AdvertiserActivityTypeId = 3; depositActivity.ActivityDescription = "Deposit-Approved"; depositActivity.AdvertiserId = 1; depositActivity.AgencyId = 23; depositActivity.BrandId = 1; depositActivity.CustomerId = "[email protected]"; depositActivity.CreatedDate = new DateTime(2015, 03, 23, 9, 30, 42); depositActivity.Domain = "deposit.23traders.com"; depositActivity.LabelId = 1; depositActivity.TransactionId = 25; depositActivity.CreatedDateStr = "2015-03-23T09:30:42+00:00"; var leadActivityDTo = new LeadActivityDTO(depositActivity, false); var serializeObject = new JsonNetAdapter().SerializeObject(leadActivityDTo); A.CallTo(() => jsonSerializer.SerializeObject(leadActivityDTo)).WithAnyArguments().Returns(serializeObject); var result = new DepositActivityFactory(jsonSerializer).CreateLeadActivity(depositActivity); Assert.AreEqual(result, leadActivityJSON); }

Slide 117

Slide 117 text

16 – 17 November, Sofia ISTACON.ORG Gherkin Language • Given • When • Then

Slide 118

Slide 118 text

16 – 17 November, Sofia ISTACON.ORG [TestMethod] public void CreateLeadActivity_CreateValidJSON() { var depositActivity = new DepositActivity(); depositActivity.ActivityTypeId = 6002; depositActivity.AdvertiserActivityTypeId = 3; depositActivity.ActivityDescription = "Deposit-Approved"; depositActivity.AdvertiserId = 1; depositActivity.AgencyId = 23; depositActivity.BrandId = 1; depositActivity.CustomerId = "[email protected]"; depositActivity.CreatedDate = new DateTime(2015, 03, 23, 9, 30, 42); depositActivity.Domain = "deposit.23traders.com"; depositActivity.LabelId = 1; depositActivity.TransactionId = 25; depositActivity.CreatedDateStr = "2015-03-23T09:30:42+00:00"; var leadActivityDTo = new LeadActivityDTO(depositActivity, false); var serializeObject = new JsonNetAdapter().SerializeObject(leadActivityDTo); A.CallTo(() => jsonSerializer.SerializeObject(leadActivityDTo)).WithAnyArguments().Returns(serializeObject); var result = new DepositActivityFactory(jsonSerializer).CreateLeadActivity(depositActivity); Assert.AreEqual(result, leadActivityJSON); }

Slide 119

Slide 119 text

16 – 17 November, Sofia ISTACON.ORG Scenario: Check monthly report Given today is 2015/05/18 And a payment was made for the 2015/04 period on 2015/04/01 When we generate agent's monthly report for 2015/03 Then payment log cannot be generated And the payment log was generated on 2015/04/01

Slide 120

Slide 120 text

16 – 17 November, Sofia ISTACON.ORG Jasmine (JavaScript) SpecFlow (.Net) Behave (Python) Cucumber (Ruby) etc

Slide 121

Slide 121 text

16 – 17 November, Sofia ISTACON.ORG Examples

Slide 122

Slide 122 text

16 – 17 November, Sofia ISTACON.ORG public virtual void SetAsConverted(…) { UpdateContactDetails(updatedContactDetails.Name); var waitDaysForDeposit = Settings.GetAppConfigInt("Days"); ClearWeights(); TrackPhoneCall(phoneNumber, convertedBy, convertedOn); ResetInteraction(); UpdateModifiedByAndOn(convertedBy.Id, convertedOn); Apply(new DepositPending(State.Id, interactionId)); } C.Complexity: Low or High?

Slide 123

Slide 123 text

16 – 17 November, Sofia ISTACON.ORG public virtual void SetAsConverted(…) { UpdateContactDetails(updatedContactDetails.Name); var waitDaysForDeposit = Settings.GetAppConfigInt("Days"); ClearWeights(); TrackPhoneCall(phoneNumber, convertedBy, convertedOn); ResetInteraction(); UpdateModifiedByAndOn(convertedBy.Id, convertedOn); Apply(new DepositPending(State.Id, interactionId)); } Unit Test or Integration Test?

Slide 124

Slide 124 text

16 – 17 November, Sofia ISTACON.ORG Active Record or Domain Model? You are working on a CRM system, and you are asked to build a service that calculates commissions for sales agents. There about 100 different commissions rules, and managers should be able to optimize them on the fly.

Slide 125

Slide 125 text

16 – 17 November, Sofia ISTACON.ORG Full Coverage by Unit or Integration Tests? You are asked to build a service that calculates commissions for sales agents. There are about 100 different commissions rules, and managers should be able to optimize them on the fly.

Slide 126

Slide 126 text

16 – 17 November, Sofia ISTACON.ORG Active Record or Domain Model?

Slide 127

Slide 127 text

16 – 17 November, Sofia ISTACON.ORG Full Coverage by Integration or Unit Tests?

Slide 128

Slide 128 text

16 – 17 November, Sofia ISTACON.ORG Summary

Slide 129

Slide 129 text

16 – 17 November, Sofia ISTACON.ORG • Write a failing Unit Test • Write code to a make it pass • Simplest design • Isolate the Class under test • Refactor • Repeat • 100% unit test coverage • Maintainable and extendable code • FAST!!! Fakes Mocks Stubs TEST-DRIVEN DESIGN

Slide 130

Slide 130 text

16 – 17 November, Sofia ISTACON.ORG • Write a failing Unit Test • Write code to a make it pass • Simplest design • Refactor • Repeat • 100% unit test coverage • FAST!!! Fakes Mocks Stubs TEST-DRIVEN DESIGN • Isolate the Class under test • Maintainable and extendable code

Slide 131

Slide 131 text

16 – 17 November, Sofia ISTACON.ORG • Write a failing Unit Test • Write code to a make it pass • Simplest design • Refactor • Repeat • 100% unit test coverage • FAST!!! TEST-DRIVEN DESIGN

Slide 132

Slide 132 text

16 – 17 November, Sofia ISTACON.ORG • Write code to a make it pass • Simplest design • Refactor • Repeat • FAST!!! TEST-DRIVEN DESIGN • Write a failing Unit Test • 100% unit test coverage

Slide 133

Slide 133 text

16 – 17 November, Sofia ISTACON.ORG • Write code to a make it pass • Simplest design • Refactor • Repeat • FAST!!! TEST-DRIVEN DESIGN • 100% unit test coverage

Slide 134

Slide 134 text

16 – 17 November, Sofia ISTACON.ORG • Write code to a make it pass • Simplest design • Refactor • Repeat • FAST!!! TEST-DRIVEN DESIGN

Slide 135

Slide 135 text

16 – 17 November, Sofia ISTACON.ORG • Write code to a make it pass • Simplest design • Refactor • Repeat • FAST!!! TEST-DRIVEN DESIGN

Slide 136

Slide 136 text

16 – 17 November, Sofia ISTACON.ORG • Write code to a make it pass
 • Repeat
 
 
 TEST-DRIVEN • Simplest design • Refactor • Fast DESIGN

Slide 137

Slide 137 text

16 – 17 November, Sofia ISTACON.ORG • Write code to a make it pass
 • Repeat
 
 
 TEST-DRIVEN • Refactor • Fast DESIGN

Slide 138

Slide 138 text

16 – 17 November, Sofia ISTACON.ORG • Write code to a make it pass
 • Repeat
 
 
 TEST-DRIVEN • Fast DESIGN

Slide 139

Slide 139 text

16 – 17 November, Sofia ISTACON.ORG • Write code to a make it pass
 • Repeat
 
 
 TEST-DRIVEN DESIGN

Slide 140

Slide 140 text

16 – 17 November, Sofia ISTACON.ORG • Write code to a make it pass
 • Repeat
 
 
 TEST-DRIVEN

Slide 141

Slide 141 text

16 – 17 November, Sofia ISTACON.ORG TDD Rebooted

Slide 142

Slide 142 text

16 – 17 November, Sofia ISTACON.ORG TEST-DRIVEN DEVELOPMENT

Slide 143

Slide 143 text

16 – 17 November, Sofia ISTACON.ORG • Learn the business domain • Analyze • Assess its complexity TEST-DRIVEN DEVELOPMENT

Slide 144

Slide 144 text

16 – 17 November, Sofia ISTACON.ORG • Learn the business domain • Analyze • Assess its complexity • Design the solution • Business logic modeling pattern • Testing strategy TEST-DRIVEN DEVELOPMENT

Slide 145

Slide 145 text

16 – 17 November, Sofia ISTACON.ORG • Learn the business domain • Analyze • Assess its complexity • Design the solution • Business logic modeling pattern • Testing strategy • Development • Start with a failing test (according to the testing strategy) • Make it pass • Refactor TEST-DRIVEN DEVELOPMENT

Slide 146

Slide 146 text

16 – 17 November, Sofia ISTACON.ORG P.S.

Slide 147

Slide 147 text

16 – 17 November, Sofia ISTACON.ORG

Slide 148

Slide 148 text

16 – 17 November, Sofia ISTACON.ORG Thank you! @vladikk vladikk.com Vladik Khononov [email protected]