SlideShare ist ein Scribd-Unternehmen logo
1 von 55
Downloaden Sie, um offline zu lesen
Overview
§  Why Mock Objects?
    §  “Mockist” vs. “Classic” TDD

    §  “Mockist” and “Classic” TDD

§  Mocks and Smalltalk:

      §    The Mocketry framework introduction
§    Examples

Mock Objects and Smalltalk                        1
Why Mock Objects?
                 Do we need Mocks at all
                          (in Smalltalk)?

Mock Objects and Smalltalk              2
Public Opinion
§    Smalltalk vs. Mock Objects?
      §  Few/rare special cases
      §  With mock you don’t test real thing

      §  Use mocks for external objects only

      §  Use other means to involve complex

          external objects
      §  Speed up by other means


Do we need Mock Objects at all?                 3
Public Opinion



…seems to be about testing



                             4
Smalltalk and Mock Objects
§    “Mock Objects” is a TDD technique
      §  … about developing systems
      §  … not just testing

      §  … useful in all languages

§    Smalltalk makes mocks
      §    much easier to use


Why Mock Objects?                         5
Why Mock Objects?
§  Cut off dependencies in tests
§  Test-Driven Decomposition

      §  Discover Responsibility (for collaborators)
      §  Thinking vs. Speculating/Fantasizing




                Seamless TDD
Why Mock Objects?                                       6
What Is The Problem?

§    Dependencies
      §    How to cut them off?


§    Novel Collaborators
      §    Where to cut?

Seamless TDD                       7
What Is The problem?

§    Dependencies
      §    How to cut them off?


§    Novel Collaborators
      §    Where to cut?

Seamless TDD                       8
Dependencies
We have:
§  System Under Development (SUD)

§  Collaborators

§  Collaborators’ collaborators …



             Complex Test

Seamless TDD — What’s the Problem?   9
So What?
We have to implement collaborators
§  … without tests

§  … loosing focus on SUD




              Digression
Seamless TDD — Dependencies      10
Dependencies: Example

§    Mocks Aren’t Stubs by Martin Fowler


§    Filling orders from warehouse




Seamless TDD — Dependencies             11
Filling Order
OrderTests >>    !
  testIsFilledIfEnoughInWarehouse!
!

| order |!
order:= Order on: 50 of: #product.!
order fillFrom: warehouse.!
self assert: order isFilled!




Seamless TDD — Dependencies     12
Filling Order
OrderTests >> !
testIsFilledIfEnoughInWarehouse!
| order warehouse |!
!
warehouse := Warehouse new.!
“Put #product there” !
“…but how?!” !
!
order := Order on: 50 of: #product.!
order fillFrom: warehouse.!
     …!

Seamless TDD — Dependencies            13
Digression Detected!
§  I develop Order
§  I don’t want to think about
    Warehouse




Seamless TDD — Dependencies       14
Filling Order
OrderTests >> !
testIsFilledIfEnoughInWarehouse!
| order warehouse |!
warehouse := Warehouse new.!
warehouse add: 50 of: #product.!
!

order := Order on: 50 of: #prod.!
order fillFrom: warehouse.!
…!

Seamless TDD — Dependencies         15
…And Even More Digression
Reduce amount of #product at the
warehouse
test…!
…!
self assert: !
  (warehouse !
    amountOf: #product)!
                     isZero!
Seamless TDD — Dependencies        16
… And Even More Digression
Another test case:

If there isn’t enough #product in the
warehouse,
§    do not fill order
§    do not remove #product from
      warehouse
Seamless TDD — Dependencies         17
… Much More Digression
       More complex test cases


 Collaborators’ logic becomes more
       and more complex…

           This can engulf
Seamless TDD — Dependencies      18
Not-So-Seamless TDD
§  SUD is Order
§  Warehouse blures SUD

      §  #add:of:
      §  #amountOf:

§    No explicit tests for Warehouse


Seamless TDD — Dependencies             19
Mocking Warehouse
OrderTests >> !
  testIsFilledIfEnoughInWarehouse!

   | order |!
     order := Order on: 50 of: #product.!
   [!
     :warehouse| !
     [order fillFrom: warehouse]!
       should satisfy:!
                 [“expectations”]!
   ] runScenario.!
   self assert: order isFilled !

Seamless TDD — Dependencies           20
Mocking Warehouse
…!
[:warehouse| !
[order fillFrom: warehouse]!
  should satisfy:!
     [(warehouse !
         has: 50 of: #product)!
             willReturn: true. !
      warehouse !
         remove: 50 of: #product]!
] runScenario.!
…!
Seamless TDD — Dependencies     21
The Mocketry
    Framework
                             Mock Objects in
                             Smalltalk World
Mock Objects and Smalltalk                22
Behavior Expectations

When you do this with SUD,
  expect that to happen
      with collaborators

Collaborators are mocked

Mocketry                     23
Behavior Expectations
    Do this      Exercise

 Expect that       Verify

                  Scenario
Mocketry                     24
Mocketry Scenario Pattern
SomeTestCases >> testCase
[

     testScenario

] runScenario

Mocketry – Behavior Expectations   25
Mocketry Scenario Pattern
SomeTestCases >> testCase
[
     [exercise]
         should strictly satisfy:
             [behaviorExpectations]
] runScenario

Mocketry – Behavior Expectations      26
Behavior Expectations
 Just send mock objects the messages
§ 

!
 they should receive
warehouse !
   has: 50 of: #product!
 Specify their reaction
§ 

(warehouse !
  has: 50 of: #product)
                       willReturn: true
Mocketry — Behavior Expectations          27
Mocketry Scenario Pattern
SomeTestCases >> testCase
[
     [exercise] should strictly satisfy: [behaviorExpectations]

     [exercise] should strictly satisfy: [behaviorExpectations]

     … do anything
] runScenario

Mocketry – Behavior Expectations                           28
Mocketry Scenario Pattern
SomeTestCases >> testCase
[ :mock |
     [exercise] should strictly satisfy: [behaviorExpectations]

     [exercise] should strictly satisfy: [behaviorExpectations]

     … do anything
] runScenario

Mocketry – Behavior Expectations                           29
Mocketry Scenario Pattern
SomeTestCases >> testCase
[ :mock |
     [exercise] should strictly satisfy: [behaviorExpectations]

     [exercise] should strictly satisfy: [behaviorExpectations]

     … do anything
] runScenario

Mocketry – Behavior Expectations                           30
Mocketry Scenario Pattern
SomeTestCases >> testCase
[ :mock1 :mock2 :mock3 |
     [exercise] should strictly satisfy: [behaviorExpectations]

     [exercise] should strictly satisfy: [behaviorExpectations]

     … do anything
] runScenario

Mocketry – Behavior Expectations                           31
Trivial Example 1
TrueTests >>
     testDoesNotExecuteIfFalseBlock
[ :block |
     [true ifFalse: block ]
          should satisfiy:
              [“nothing expected”]
] runScenario


Mocketry – Behavior Expectations      32
Trivial Example 2
TrueTests >>
     testExecutesIfTrueBlock
[ :block |
     [true ifTrue: block]
          should satisfiy:
               [block value]
] runScenario

Mocketry – Behavior Expectations   33
State Specification DSL
§    resultObject should <expectation>
      §  result should be: anotherObject
      §  result should equal: anotherObject

      §  …




Mocketry                                       34
Mocketry
§  There is much more…
§  Ask me

§  …or Dennis Kudryashov (the

    Author)




                                 35
Mocking Warehouse
OrderTests >> !
testIsFilledIfEnoughInWarehouse!
| order |!
order := Order on: 50 of: #product.!
!

[:warehouse| !
  [order fillFrom: warehouse]!
    should satisfy:!
   [(warehouse has: 50 of: #product)!
           willReturn: true. !
    warehouse remove: 50 of: #product]!
] runScenario.!
!
self assert: order isFilled !

Seamless TDD — Dependencies — Example   36
Mocking Warehouse
OrderTests >> !
testIsNotFilledIfNotEnoughInWarehouse!
| order |!
order := Order on: #amount of: #product.!
[:warehouse| !
  [order fillFrom: warehouse]!
    should satisfy:!
   [(warehouse has: 50 of: #product)!
           willReturn: false. !
    “Nothing else is expected” ]!
] runScenario.!
self assert: order isFilled !

Seamless TDD — Dependencies                 37
What We Get
§  No need to implement Warehouse
§  Just specify expectations

§  … right in the test

§    Focus on the SUD



Why Mock Objects                     38
What’s the problem?
§  Dependencies
§  Novel Сollaborators




Seamless TDD              39
Where to Start?
         A novel system to implement

                 Object 2
   Object 1                     Object N
                            …
                Object 3

Seamless TDD — Novel Collaborators         40
Where to Cut?
         A novel system to implement
                          Feature
       Feature Feature Feature
      Feature            Feature
                 Feature
           Feature
                       Feature
        FeatureFeature

Seamless TDD — Novel Collaborators     41
Where to Start?
§    Try to guess
      §  … and be ready to abandon test(s)
      §  … or get a mess

                   Or
§  Analyze thoroughly

      §  … up-front decomposition
      §  … without tests — just a fantasy

Seamless TDD — Novel Collaborators            42
Novel Collaborators: Example

Bulls and Cows Game
§  Computer generates a secret key

      §    e.g., a 4-digit number
§    Human player tries to disclose it


Seamless TDD — Novel Collaborators        43
Bulls and Cows Game
Scenario:
§  User creates a game object

§  User starts the game

      §    Game should generate a key
§    …


Seamless TDD — Novel Collaborators       44
testGeneratesKeyOnStart
!
!
    self assert: key …?!
    “How to represent key?!”!




Seamless TDD — Novel Collaborators   45
What Can I Do?
§    Spontaneous representation
      §    Do you feel lucky?
§    Analyze thoroughly
      §    Give up TDD
§    Postpone the test
      §    Not a solution


Seamless TDD — Novel Collaborators   46
What Can I Do?
§  …
§  Create a new class for key

      §    Unnecessary complexity?




Seamless TDD — Novel Collaborators    47
What Can I Do?


       That was a Digression!




Seamless TDD — Novel Collaborators   48
testGeneratesKeyOnStart
|key|!
game start.!
key := game key.!
self assert: !
  !key isKindOf: Code!



Seamless TDD — Novel Collaborators   49
testGeneratesKeyOnStart
[ :keyGen |!
 game keyGenerator: keyGen.!
 [ game start ]!
   should satisfy:!
     [keyGen createKey!
        willReturn: #key]!
 game key should be: #key!
] runScenario.!
Seamless TDD — Novel Collaborators   50
What We Get
§    Key generation functionality
      §  is revealed
      §  moved to another object

§    Dependency Injection
      §  fake key can be created for tests
      §  KeyGenerator refactored to Turn

§    No risk of incorrect decision
Seamless TDD — Novel Collaborators            51
What We Get
Seamless TDD:
§  No digression

§  No up-front decomposition

§  No up-front design

§  No speculating / fantasizing




Seamless TDD — Novel Collaborators   52
Complete Example

Mock Objects For Top-Down Design
by Bulls-and-Cows Example

            Just ask!



                               53
Classic vs. Mockist TDD

         State vs. Behavior?
         Result vs. Intention?
           No contradiction!
       Mockist approach
   complements “classic” TDD
Seamless TDD                     54
Classic and Mockist TDD

§    Top-Down with Mockist TDD
      §    Analysis and Decomposition

§    Bottom-Up with Classic TDD
      §    Synthesis and “real-object” testing


                                                  55

Weitere ähnliche Inhalte

Ähnlich wie Mock Objects and Smalltalk

Behaviour Driven Development and Thinking About Testing
Behaviour Driven Development and Thinking About TestingBehaviour Driven Development and Thinking About Testing
Behaviour Driven Development and Thinking About Testingdn
 
Bdd and-testing
Bdd and-testingBdd and-testing
Bdd and-testingmalcolmt
 
Software testing (2) trainingin-mumbai...
Software testing (2) trainingin-mumbai...Software testing (2) trainingin-mumbai...
Software testing (2) trainingin-mumbai...vibrantuser
 
Just Mock It - Mocks and Stubs
Just Mock It - Mocks and StubsJust Mock It - Mocks and Stubs
Just Mock It - Mocks and StubsGavin Pickin
 
Software testing (2) trainingin-mumbai
Software testing (2) trainingin-mumbaiSoftware testing (2) trainingin-mumbai
Software testing (2) trainingin-mumbaivibrantuser
 
Unit Testing like a Pro - The Circle of Purity
Unit Testing like a Pro - The Circle of PurityUnit Testing like a Pro - The Circle of Purity
Unit Testing like a Pro - The Circle of PurityVictor Rentea
 
CBDW2014 - MockBox, get ready to mock your socks off!
CBDW2014 - MockBox, get ready to mock your socks off!CBDW2014 - MockBox, get ready to mock your socks off!
CBDW2014 - MockBox, get ready to mock your socks off!Ortus Solutions, Corp
 
How and what to unit test
How and what to unit testHow and what to unit test
How and what to unit testEugenio Lentini
 
TDD: seriously, try it! 
TDD: seriously, try it! TDD: seriously, try it! 
TDD: seriously, try it! Nacho Cougil
 
Developer testing 201: When to Mock and When to Integrate
Developer testing 201: When to Mock and When to IntegrateDeveloper testing 201: When to Mock and When to Integrate
Developer testing 201: When to Mock and When to IntegrateLB Denker
 
Theory Of Constraints - Agile Tour 2013 Craig Strong & Daryn Holmes
Theory Of Constraints - Agile Tour 2013 Craig Strong &  Daryn HolmesTheory Of Constraints - Agile Tour 2013 Craig Strong &  Daryn Holmes
Theory Of Constraints - Agile Tour 2013 Craig Strong & Daryn Holmesstrongandagile.co.uk
 
Anatomy of Test Driven Development
Anatomy of Test Driven DevelopmentAnatomy of Test Driven Development
Anatomy of Test Driven DevelopmentDhaval Shah
 
Real developers-dont-need-unit-tests
Real developers-dont-need-unit-testsReal developers-dont-need-unit-tests
Real developers-dont-need-unit-testsSkills Matter
 
It's all about behaviour, also in php - phpspec
It's all about behaviour, also in php - phpspecIt's all about behaviour, also in php - phpspec
It's all about behaviour, also in php - phpspecGiulio De Donato
 
Mocking in Python
Mocking in PythonMocking in Python
Mocking in PythonExcella
 
Mocking in python
Mocking in pythonMocking in python
Mocking in pythonOoblioob
 

Ähnlich wie Mock Objects and Smalltalk (20)

Behaviour Driven Development and Thinking About Testing
Behaviour Driven Development and Thinking About TestingBehaviour Driven Development and Thinking About Testing
Behaviour Driven Development and Thinking About Testing
 
Bdd and-testing
Bdd and-testingBdd and-testing
Bdd and-testing
 
Software testing (2) trainingin-mumbai...
Software testing (2) trainingin-mumbai...Software testing (2) trainingin-mumbai...
Software testing (2) trainingin-mumbai...
 
Just Mock It - Mocks and Stubs
Just Mock It - Mocks and StubsJust Mock It - Mocks and Stubs
Just Mock It - Mocks and Stubs
 
Testing gone-right
Testing gone-rightTesting gone-right
Testing gone-right
 
Software testing (2) trainingin-mumbai
Software testing (2) trainingin-mumbaiSoftware testing (2) trainingin-mumbai
Software testing (2) trainingin-mumbai
 
Unit Testing like a Pro - The Circle of Purity
Unit Testing like a Pro - The Circle of PurityUnit Testing like a Pro - The Circle of Purity
Unit Testing like a Pro - The Circle of Purity
 
CBDW2014 - MockBox, get ready to mock your socks off!
CBDW2014 - MockBox, get ready to mock your socks off!CBDW2014 - MockBox, get ready to mock your socks off!
CBDW2014 - MockBox, get ready to mock your socks off!
 
How and what to unit test
How and what to unit testHow and what to unit test
How and what to unit test
 
TDD: seriously, try it! 
TDD: seriously, try it! TDD: seriously, try it! 
TDD: seriously, try it! 
 
Developer testing 201: When to Mock and When to Integrate
Developer testing 201: When to Mock and When to IntegrateDeveloper testing 201: When to Mock and When to Integrate
Developer testing 201: When to Mock and When to Integrate
 
Theory Of Constraints - Agile Tour 2013 Craig Strong & Daryn Holmes
Theory Of Constraints - Agile Tour 2013 Craig Strong &  Daryn HolmesTheory Of Constraints - Agile Tour 2013 Craig Strong &  Daryn Holmes
Theory Of Constraints - Agile Tour 2013 Craig Strong & Daryn Holmes
 
Unit Testing in Swift
Unit Testing in SwiftUnit Testing in Swift
Unit Testing in Swift
 
Anatomy of Test Driven Development
Anatomy of Test Driven DevelopmentAnatomy of Test Driven Development
Anatomy of Test Driven Development
 
Real developers-dont-need-unit-tests
Real developers-dont-need-unit-testsReal developers-dont-need-unit-tests
Real developers-dont-need-unit-tests
 
Real developers-dont-need-unit-tests
Real developers-dont-need-unit-testsReal developers-dont-need-unit-tests
Real developers-dont-need-unit-tests
 
It's all about behaviour, also in php - phpspec
It's all about behaviour, also in php - phpspecIt's all about behaviour, also in php - phpspec
It's all about behaviour, also in php - phpspec
 
TDD talk
TDD talkTDD talk
TDD talk
 
Mocking in Python
Mocking in PythonMocking in Python
Mocking in Python
 
Mocking in python
Mocking in pythonMocking in python
Mocking in python
 

Mehr von ESUG

Workshop: Identifying concept inventories in agile programming
Workshop: Identifying concept inventories in agile programmingWorkshop: Identifying concept inventories in agile programming
Workshop: Identifying concept inventories in agile programmingESUG
 
Technical documentation support in Pharo
Technical documentation support in PharoTechnical documentation support in Pharo
Technical documentation support in PharoESUG
 
The Pharo Debugger and Debugging tools: Advances and Roadmap
The Pharo Debugger and Debugging tools: Advances and RoadmapThe Pharo Debugger and Debugging tools: Advances and Roadmap
The Pharo Debugger and Debugging tools: Advances and RoadmapESUG
 
Sequence: Pipeline modelling in Pharo
Sequence: Pipeline modelling in PharoSequence: Pipeline modelling in Pharo
Sequence: Pipeline modelling in PharoESUG
 
Migration process from monolithic to micro frontend architecture in mobile ap...
Migration process from monolithic to micro frontend architecture in mobile ap...Migration process from monolithic to micro frontend architecture in mobile ap...
Migration process from monolithic to micro frontend architecture in mobile ap...ESUG
 
Analyzing Dart Language with Pharo: Report and early results
Analyzing Dart Language with Pharo: Report and early resultsAnalyzing Dart Language with Pharo: Report and early results
Analyzing Dart Language with Pharo: Report and early resultsESUG
 
Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6
Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6
Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6ESUG
 
A Unit Test Metamodel for Test Generation
A Unit Test Metamodel for Test GenerationA Unit Test Metamodel for Test Generation
A Unit Test Metamodel for Test GenerationESUG
 
Creating Unit Tests Using Genetic Programming
Creating Unit Tests Using Genetic ProgrammingCreating Unit Tests Using Genetic Programming
Creating Unit Tests Using Genetic ProgrammingESUG
 
Threaded-Execution and CPS Provide Smooth Switching Between Execution Modes
Threaded-Execution and CPS Provide Smooth Switching Between Execution ModesThreaded-Execution and CPS Provide Smooth Switching Between Execution Modes
Threaded-Execution and CPS Provide Smooth Switching Between Execution ModesESUG
 
Exploring GitHub Actions through EGAD: An Experience Report
Exploring GitHub Actions through EGAD: An Experience ReportExploring GitHub Actions through EGAD: An Experience Report
Exploring GitHub Actions through EGAD: An Experience ReportESUG
 
Pharo: a reflective language A first systematic analysis of reflective APIs
Pharo: a reflective language A first systematic analysis of reflective APIsPharo: a reflective language A first systematic analysis of reflective APIs
Pharo: a reflective language A first systematic analysis of reflective APIsESUG
 
Garbage Collector Tuning
Garbage Collector TuningGarbage Collector Tuning
Garbage Collector TuningESUG
 
Improving Performance Through Object Lifetime Profiling: the DataFrame Case
Improving Performance Through Object Lifetime Profiling: the DataFrame CaseImproving Performance Through Object Lifetime Profiling: the DataFrame Case
Improving Performance Through Object Lifetime Profiling: the DataFrame CaseESUG
 
Pharo DataFrame: Past, Present, and Future
Pharo DataFrame: Past, Present, and FuturePharo DataFrame: Past, Present, and Future
Pharo DataFrame: Past, Present, and FutureESUG
 
thisContext in the Debugger
thisContext in the DebuggerthisContext in the Debugger
thisContext in the DebuggerESUG
 
Websockets for Fencing Score
Websockets for Fencing ScoreWebsockets for Fencing Score
Websockets for Fencing ScoreESUG
 
ShowUs: PharoJS.org Develop in Pharo, Run on JavaScript
ShowUs: PharoJS.org Develop in Pharo, Run on JavaScriptShowUs: PharoJS.org Develop in Pharo, Run on JavaScript
ShowUs: PharoJS.org Develop in Pharo, Run on JavaScriptESUG
 
Advanced Object- Oriented Design Mooc
Advanced Object- Oriented Design MoocAdvanced Object- Oriented Design Mooc
Advanced Object- Oriented Design MoocESUG
 
A New Architecture Reconciling Refactorings and Transformations
A New Architecture Reconciling Refactorings and TransformationsA New Architecture Reconciling Refactorings and Transformations
A New Architecture Reconciling Refactorings and TransformationsESUG
 

Mehr von ESUG (20)

Workshop: Identifying concept inventories in agile programming
Workshop: Identifying concept inventories in agile programmingWorkshop: Identifying concept inventories in agile programming
Workshop: Identifying concept inventories in agile programming
 
Technical documentation support in Pharo
Technical documentation support in PharoTechnical documentation support in Pharo
Technical documentation support in Pharo
 
The Pharo Debugger and Debugging tools: Advances and Roadmap
The Pharo Debugger and Debugging tools: Advances and RoadmapThe Pharo Debugger and Debugging tools: Advances and Roadmap
The Pharo Debugger and Debugging tools: Advances and Roadmap
 
Sequence: Pipeline modelling in Pharo
Sequence: Pipeline modelling in PharoSequence: Pipeline modelling in Pharo
Sequence: Pipeline modelling in Pharo
 
Migration process from monolithic to micro frontend architecture in mobile ap...
Migration process from monolithic to micro frontend architecture in mobile ap...Migration process from monolithic to micro frontend architecture in mobile ap...
Migration process from monolithic to micro frontend architecture in mobile ap...
 
Analyzing Dart Language with Pharo: Report and early results
Analyzing Dart Language with Pharo: Report and early resultsAnalyzing Dart Language with Pharo: Report and early results
Analyzing Dart Language with Pharo: Report and early results
 
Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6
Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6
Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6
 
A Unit Test Metamodel for Test Generation
A Unit Test Metamodel for Test GenerationA Unit Test Metamodel for Test Generation
A Unit Test Metamodel for Test Generation
 
Creating Unit Tests Using Genetic Programming
Creating Unit Tests Using Genetic ProgrammingCreating Unit Tests Using Genetic Programming
Creating Unit Tests Using Genetic Programming
 
Threaded-Execution and CPS Provide Smooth Switching Between Execution Modes
Threaded-Execution and CPS Provide Smooth Switching Between Execution ModesThreaded-Execution and CPS Provide Smooth Switching Between Execution Modes
Threaded-Execution and CPS Provide Smooth Switching Between Execution Modes
 
Exploring GitHub Actions through EGAD: An Experience Report
Exploring GitHub Actions through EGAD: An Experience ReportExploring GitHub Actions through EGAD: An Experience Report
Exploring GitHub Actions through EGAD: An Experience Report
 
Pharo: a reflective language A first systematic analysis of reflective APIs
Pharo: a reflective language A first systematic analysis of reflective APIsPharo: a reflective language A first systematic analysis of reflective APIs
Pharo: a reflective language A first systematic analysis of reflective APIs
 
Garbage Collector Tuning
Garbage Collector TuningGarbage Collector Tuning
Garbage Collector Tuning
 
Improving Performance Through Object Lifetime Profiling: the DataFrame Case
Improving Performance Through Object Lifetime Profiling: the DataFrame CaseImproving Performance Through Object Lifetime Profiling: the DataFrame Case
Improving Performance Through Object Lifetime Profiling: the DataFrame Case
 
Pharo DataFrame: Past, Present, and Future
Pharo DataFrame: Past, Present, and FuturePharo DataFrame: Past, Present, and Future
Pharo DataFrame: Past, Present, and Future
 
thisContext in the Debugger
thisContext in the DebuggerthisContext in the Debugger
thisContext in the Debugger
 
Websockets for Fencing Score
Websockets for Fencing ScoreWebsockets for Fencing Score
Websockets for Fencing Score
 
ShowUs: PharoJS.org Develop in Pharo, Run on JavaScript
ShowUs: PharoJS.org Develop in Pharo, Run on JavaScriptShowUs: PharoJS.org Develop in Pharo, Run on JavaScript
ShowUs: PharoJS.org Develop in Pharo, Run on JavaScript
 
Advanced Object- Oriented Design Mooc
Advanced Object- Oriented Design MoocAdvanced Object- Oriented Design Mooc
Advanced Object- Oriented Design Mooc
 
A New Architecture Reconciling Refactorings and Transformations
A New Architecture Reconciling Refactorings and TransformationsA New Architecture Reconciling Refactorings and Transformations
A New Architecture Reconciling Refactorings and Transformations
 

Kürzlich hochgeladen

DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 

Kürzlich hochgeladen (20)

DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 

Mock Objects and Smalltalk

  • 1. Overview §  Why Mock Objects? §  “Mockist” vs. “Classic” TDD §  “Mockist” and “Classic” TDD §  Mocks and Smalltalk: §  The Mocketry framework introduction §  Examples Mock Objects and Smalltalk 1
  • 2. Why Mock Objects? Do we need Mocks at all (in Smalltalk)? Mock Objects and Smalltalk 2
  • 3. Public Opinion §  Smalltalk vs. Mock Objects? §  Few/rare special cases §  With mock you don’t test real thing §  Use mocks for external objects only §  Use other means to involve complex external objects §  Speed up by other means Do we need Mock Objects at all? 3
  • 4. Public Opinion …seems to be about testing 4
  • 5. Smalltalk and Mock Objects §  “Mock Objects” is a TDD technique §  … about developing systems §  … not just testing §  … useful in all languages §  Smalltalk makes mocks §  much easier to use Why Mock Objects? 5
  • 6. Why Mock Objects? §  Cut off dependencies in tests §  Test-Driven Decomposition §  Discover Responsibility (for collaborators) §  Thinking vs. Speculating/Fantasizing Seamless TDD Why Mock Objects? 6
  • 7. What Is The Problem? §  Dependencies §  How to cut them off? §  Novel Collaborators §  Where to cut? Seamless TDD 7
  • 8. What Is The problem? §  Dependencies §  How to cut them off? §  Novel Collaborators §  Where to cut? Seamless TDD 8
  • 9. Dependencies We have: §  System Under Development (SUD) §  Collaborators §  Collaborators’ collaborators … Complex Test Seamless TDD — What’s the Problem? 9
  • 10. So What? We have to implement collaborators §  … without tests §  … loosing focus on SUD Digression Seamless TDD — Dependencies 10
  • 11. Dependencies: Example §  Mocks Aren’t Stubs by Martin Fowler §  Filling orders from warehouse Seamless TDD — Dependencies 11
  • 12. Filling Order OrderTests >> ! testIsFilledIfEnoughInWarehouse! ! | order |! order:= Order on: 50 of: #product.! order fillFrom: warehouse.! self assert: order isFilled! Seamless TDD — Dependencies 12
  • 13. Filling Order OrderTests >> ! testIsFilledIfEnoughInWarehouse! | order warehouse |! ! warehouse := Warehouse new.! “Put #product there” ! “…but how?!” ! ! order := Order on: 50 of: #product.! order fillFrom: warehouse.! …! Seamless TDD — Dependencies 13
  • 14. Digression Detected! §  I develop Order §  I don’t want to think about Warehouse Seamless TDD — Dependencies 14
  • 15. Filling Order OrderTests >> ! testIsFilledIfEnoughInWarehouse! | order warehouse |! warehouse := Warehouse new.! warehouse add: 50 of: #product.! ! order := Order on: 50 of: #prod.! order fillFrom: warehouse.! …! Seamless TDD — Dependencies 15
  • 16. …And Even More Digression Reduce amount of #product at the warehouse test…! …! self assert: ! (warehouse ! amountOf: #product)! isZero! Seamless TDD — Dependencies 16
  • 17. … And Even More Digression Another test case: If there isn’t enough #product in the warehouse, §  do not fill order §  do not remove #product from warehouse Seamless TDD — Dependencies 17
  • 18. … Much More Digression More complex test cases Collaborators’ logic becomes more and more complex… This can engulf Seamless TDD — Dependencies 18
  • 19. Not-So-Seamless TDD §  SUD is Order §  Warehouse blures SUD §  #add:of: §  #amountOf: §  No explicit tests for Warehouse Seamless TDD — Dependencies 19
  • 20. Mocking Warehouse OrderTests >> ! testIsFilledIfEnoughInWarehouse! | order |! order := Order on: 50 of: #product.! [! :warehouse| ! [order fillFrom: warehouse]! should satisfy:! [“expectations”]! ] runScenario.! self assert: order isFilled ! Seamless TDD — Dependencies 20
  • 21. Mocking Warehouse …! [:warehouse| ! [order fillFrom: warehouse]! should satisfy:! [(warehouse ! has: 50 of: #product)! willReturn: true. ! warehouse ! remove: 50 of: #product]! ] runScenario.! …! Seamless TDD — Dependencies 21
  • 22. The Mocketry Framework Mock Objects in Smalltalk World Mock Objects and Smalltalk 22
  • 23. Behavior Expectations When you do this with SUD, expect that to happen with collaborators Collaborators are mocked Mocketry 23
  • 24. Behavior Expectations Do this Exercise Expect that Verify Scenario Mocketry 24
  • 25. Mocketry Scenario Pattern SomeTestCases >> testCase [ testScenario ] runScenario Mocketry – Behavior Expectations 25
  • 26. Mocketry Scenario Pattern SomeTestCases >> testCase [ [exercise] should strictly satisfy: [behaviorExpectations] ] runScenario Mocketry – Behavior Expectations 26
  • 27. Behavior Expectations Just send mock objects the messages §  ! they should receive warehouse ! has: 50 of: #product! Specify their reaction §  (warehouse ! has: 50 of: #product) willReturn: true Mocketry — Behavior Expectations 27
  • 28. Mocketry Scenario Pattern SomeTestCases >> testCase [ [exercise] should strictly satisfy: [behaviorExpectations] [exercise] should strictly satisfy: [behaviorExpectations] … do anything ] runScenario Mocketry – Behavior Expectations 28
  • 29. Mocketry Scenario Pattern SomeTestCases >> testCase [ :mock | [exercise] should strictly satisfy: [behaviorExpectations] [exercise] should strictly satisfy: [behaviorExpectations] … do anything ] runScenario Mocketry – Behavior Expectations 29
  • 30. Mocketry Scenario Pattern SomeTestCases >> testCase [ :mock | [exercise] should strictly satisfy: [behaviorExpectations] [exercise] should strictly satisfy: [behaviorExpectations] … do anything ] runScenario Mocketry – Behavior Expectations 30
  • 31. Mocketry Scenario Pattern SomeTestCases >> testCase [ :mock1 :mock2 :mock3 | [exercise] should strictly satisfy: [behaviorExpectations] [exercise] should strictly satisfy: [behaviorExpectations] … do anything ] runScenario Mocketry – Behavior Expectations 31
  • 32. Trivial Example 1 TrueTests >> testDoesNotExecuteIfFalseBlock [ :block | [true ifFalse: block ] should satisfiy: [“nothing expected”] ] runScenario Mocketry – Behavior Expectations 32
  • 33. Trivial Example 2 TrueTests >> testExecutesIfTrueBlock [ :block | [true ifTrue: block] should satisfiy: [block value] ] runScenario Mocketry – Behavior Expectations 33
  • 34. State Specification DSL §  resultObject should <expectation> §  result should be: anotherObject §  result should equal: anotherObject §  … Mocketry 34
  • 35. Mocketry §  There is much more… §  Ask me §  …or Dennis Kudryashov (the Author) 35
  • 36. Mocking Warehouse OrderTests >> ! testIsFilledIfEnoughInWarehouse! | order |! order := Order on: 50 of: #product.! ! [:warehouse| ! [order fillFrom: warehouse]! should satisfy:! [(warehouse has: 50 of: #product)! willReturn: true. ! warehouse remove: 50 of: #product]! ] runScenario.! ! self assert: order isFilled ! Seamless TDD — Dependencies — Example 36
  • 37. Mocking Warehouse OrderTests >> ! testIsNotFilledIfNotEnoughInWarehouse! | order |! order := Order on: #amount of: #product.! [:warehouse| ! [order fillFrom: warehouse]! should satisfy:! [(warehouse has: 50 of: #product)! willReturn: false. ! “Nothing else is expected” ]! ] runScenario.! self assert: order isFilled ! Seamless TDD — Dependencies 37
  • 38. What We Get §  No need to implement Warehouse §  Just specify expectations §  … right in the test §  Focus on the SUD Why Mock Objects 38
  • 39. What’s the problem? §  Dependencies §  Novel Сollaborators Seamless TDD 39
  • 40. Where to Start? A novel system to implement Object 2 Object 1 Object N … Object 3 Seamless TDD — Novel Collaborators 40
  • 41. Where to Cut? A novel system to implement Feature Feature Feature Feature Feature Feature Feature Feature Feature FeatureFeature Seamless TDD — Novel Collaborators 41
  • 42. Where to Start? §  Try to guess §  … and be ready to abandon test(s) §  … or get a mess Or §  Analyze thoroughly §  … up-front decomposition §  … without tests — just a fantasy Seamless TDD — Novel Collaborators 42
  • 43. Novel Collaborators: Example Bulls and Cows Game §  Computer generates a secret key §  e.g., a 4-digit number §  Human player tries to disclose it Seamless TDD — Novel Collaborators 43
  • 44. Bulls and Cows Game Scenario: §  User creates a game object §  User starts the game §  Game should generate a key §  … Seamless TDD — Novel Collaborators 44
  • 45. testGeneratesKeyOnStart ! ! self assert: key …?! “How to represent key?!”! Seamless TDD — Novel Collaborators 45
  • 46. What Can I Do? §  Spontaneous representation §  Do you feel lucky? §  Analyze thoroughly §  Give up TDD §  Postpone the test §  Not a solution Seamless TDD — Novel Collaborators 46
  • 47. What Can I Do? §  … §  Create a new class for key §  Unnecessary complexity? Seamless TDD — Novel Collaborators 47
  • 48. What Can I Do? That was a Digression! Seamless TDD — Novel Collaborators 48
  • 49. testGeneratesKeyOnStart |key|! game start.! key := game key.! self assert: ! !key isKindOf: Code! Seamless TDD — Novel Collaborators 49
  • 50. testGeneratesKeyOnStart [ :keyGen |! game keyGenerator: keyGen.! [ game start ]! should satisfy:! [keyGen createKey! willReturn: #key]! game key should be: #key! ] runScenario.! Seamless TDD — Novel Collaborators 50
  • 51. What We Get §  Key generation functionality §  is revealed §  moved to another object §  Dependency Injection §  fake key can be created for tests §  KeyGenerator refactored to Turn §  No risk of incorrect decision Seamless TDD — Novel Collaborators 51
  • 52. What We Get Seamless TDD: §  No digression §  No up-front decomposition §  No up-front design §  No speculating / fantasizing Seamless TDD — Novel Collaborators 52
  • 53. Complete Example Mock Objects For Top-Down Design by Bulls-and-Cows Example Just ask! 53
  • 54. Classic vs. Mockist TDD State vs. Behavior? Result vs. Intention? No contradiction! Mockist approach complements “classic” TDD Seamless TDD 54
  • 55. Classic and Mockist TDD §  Top-Down with Mockist TDD §  Analysis and Decomposition §  Bottom-Up with Classic TDD §  Synthesis and “real-object” testing 55