SlideShare a Scribd company logo
ESUG – 1sep2009 - 0 Just-in-time Resourcing: fast tests in SUnit 3.2 and friends Niall Ross, Cincom 1 September 2009 Version 1.0 SUnit
SUnit Once upon a time there were three classes ... TestCase TestSuite TestResult ... and then there was a fourth TestResource This talk is about: (mainly) TestResources in SUnit 3.2 (briefly) SUnit status
TestResource is an optimisation Kent Beck’s rules of optimisation Rule 1:  do it later Rule 2:  see rule 1 eXtreme Programming practices Test-driven development  “ But my tests are too slow.” Refactoring “ So refactor your tests to be fast.” enter  TestResource and (somewhat later) explanations of it Make it run Make it right Make it fast
Problems with TestResource XP style :  “Do it later” / “You won’t need it”: Every resource set up before any test is run If one resource of one test in a suite of 15,000+ fails … …  the run does nothing – not what you want to see when next you look XP Style : refactoring + “last make it fast” MyTestCase>>setUp … self assert: databaseSession isOnline description: ‘not online’. Tests getting slow?  Refactor to a TestResource. MyTestResource(Object)>>doesNotUnderstand: #assert:description:
Problems with TestResources Resources can  compete   with  other resources: e.g. connect to one DB at a time, several DBs to test I coded the CompetingResource pattern: in SUnit 3.1 and earlier, not easy ! Stephane D and Martin K also had patterns – also not easy Resources can  rely on  other resources: Tests (and resources) can have ordered resources MyTestCase class>>resources ^Array wth: ConnectToDBResource with: AddTestDataToDBResource resource setUp (tearDown)  not  in order (reverse order) resource setUp / tearDown  after  resource that needs it
What has changed in TestResource Resources are made available just-in-time: first test that needs it prompts set up later tests that need it see it has (or failed to) set up tearDown guaranteed at end of run; can be done anytime resetting in a test’s tearDown trades performance for test isolation Resources understand #assert:… protocol setUp and isAvailable run inside the handler in end-run tearDown, #assert: is just better protocol for same behaviour  Resource-processing is ordered a test’s resources setUp in order and tearDown in reverse order a resource’s resources setUp before it and tearDown after it
Code changes: just-in-time resourcing TestCase>>runCase self resources do: [:each | self assert: each isAvailable   description: 'Unavailable resource ', each name, ' requested by test ', self printString]. [self setUp. self performTest] sunitEnsure: [self tearDown]. TestSuite>>run | result | result := TestResult new. self resources do: [ :each | each isAvailable ifFalse: [^each signalInitializationError]]. [self run: result] sunitEnsure: [self resources  reverseDo : [:each | each reset]]. ^result
Code changes: 3-valued logic for ‘current’ TestResource class>>isAvailable current isNil ifTrue: [ self makeAvailable ]. ^ self isAlreadyAvailable TestResource class>>makeAvailable | candidate | current := false.  "any object not nil and not an instance of me would do" self resources do: [:each | self assert: each isAvailable   description: 'Unavailable resource ', each name, ' requested by resource ', self name]. candidate := self new. candidate isAvailable ifTrue: [current := candidate]. TestResource class>>isAlreadyAvailable ^current class == self
Class changes Once upon a time there were three classes ... TestCase, TestSuite and TestResult ... and then there was a fourth ... TestResource ... and now a fifth ... TestAsserter : abstract superclass of TestCase TestResource any user-created TestCase delegate class ( ... and that’s enough ! )
Any impact on Users ? Logging TestCase methods moved to the class-side #isLogging, and #failureLog (and #logFailure: is on both sides) (So, who here overrides #isLogging or #failureLog ?) Profiling a test… method’s time: no impact a test suite’s overall time: no impact a test’s time in #runCase: sometimes see resource time time moved from start of suite’s #run to start of (some) tests’ #runCase Any objections, voice them now !
SUnit 3.2 Make your tests run Make your tests right Make your tests fast (resources can help) Thanks to Yuri Mironenko, Dale Henrichs, James Foster, Tim MacKinnon for helping me port to Squeak, Gemstone and Dolphin.
SUnit and Friends SUnit: cross-dialect, backward-compatible, 3-5 classes Add-ons: SUnitXProcPatterns, SUnitResourcePatterns, etc. UIs: RBSUnitExtensions  SUnitBrowser, Squeak TestRunner, etc. SUnitToo: VW-specific, experimental, 11 classes SUnit-Bridge2SU2 maps SUnit tests to SUnitToo tests Assessments: VW-specific, configurable, 40+ classes transparent  bridges configurable for SUnit, SUnitToo, etc. GemStone’s test framework … SUnit wants ideas SUnit will remain cross-dialect, backward-compatible, small

More Related Content

PPTX
First adoption hackathon at BGJUG
Ivan Ivanov
 
PPTX
Test your tests with PIT framework
Darko Špoljarić
 
PDF
Testing With Test::Class
Curtis Poe
 
PDF
Java Testing With Spock - Ken Sipe (Trexin Consulting)
jaxLondonConference
 
PPTX
Selenium TestNG
KadarkaraiSelvam
 
KEY
Testing Zen
day
 
PPTX
TestNG vs Junit
Büşra İçöz
 
PDF
Load Testing with RedLine13: Or getting paid to DoS your own systems
Jason Lotito
 
First adoption hackathon at BGJUG
Ivan Ivanov
 
Test your tests with PIT framework
Darko Špoljarić
 
Testing With Test::Class
Curtis Poe
 
Java Testing With Spock - Ken Sipe (Trexin Consulting)
jaxLondonConference
 
Selenium TestNG
KadarkaraiSelvam
 
Testing Zen
day
 
TestNG vs Junit
Büşra İçöz
 
Load Testing with RedLine13: Or getting paid to DoS your own systems
Jason Lotito
 

What's hot (20)

PPT
Unit testing with Spock Framework
Eugene Dvorkin
 
PPT
jUnit
sundar22in
 
PDF
Be smart when testing your Akka code
Mykhailo Kotsur
 
DOCX
Soaoui
Vikas Singh
 
PDF
Scala test
Inphina Technologies
 
PDF
Akka Testkit Patterns
Mykhailo Kotsur
 
PPTX
J unit스터디슬라이드
ksain
 
PPT
Google C++ Testing Framework in Visual Studio 2008
Andrea Francia
 
PDF
Structured Testing Framework
serzar
 
PDF
A fresh look at Java Enterprise Application testing with Arquillian
Vineet Reynolds
 
PPTX
Cassandra Codebase 2011
gdusbabek
 
PDF
Maintaining Your Tests At Scale
Trent Willis
 
PDF
JUnit 4 Can it still teach us something? - Andrzej Jóźwiak - Kariera IT Łodź ...
Andrzej Jóźwiak
 
PDF
Andro sec rl-prototype-finalproject
LiadBercovich
 
ODP
Software Testing
Lambert Lum
 
PPTX
Getting to Know the Cassandra Codebase
gdusbabek
 
PDF
Javascript tdd byandreapaciolla
Andrea Paciolla
 
PPTX
Maven TestNg frame work (1) (1)
Gopi Raghavendra
 
ODP
Grails unit testing
pleeps
 
PDF
Test Driven Development
Sheeju Alex
 
Unit testing with Spock Framework
Eugene Dvorkin
 
jUnit
sundar22in
 
Be smart when testing your Akka code
Mykhailo Kotsur
 
Soaoui
Vikas Singh
 
Akka Testkit Patterns
Mykhailo Kotsur
 
J unit스터디슬라이드
ksain
 
Google C++ Testing Framework in Visual Studio 2008
Andrea Francia
 
Structured Testing Framework
serzar
 
A fresh look at Java Enterprise Application testing with Arquillian
Vineet Reynolds
 
Cassandra Codebase 2011
gdusbabek
 
Maintaining Your Tests At Scale
Trent Willis
 
JUnit 4 Can it still teach us something? - Andrzej Jóźwiak - Kariera IT Łodź ...
Andrzej Jóźwiak
 
Andro sec rl-prototype-finalproject
LiadBercovich
 
Software Testing
Lambert Lum
 
Getting to Know the Cassandra Codebase
gdusbabek
 
Javascript tdd byandreapaciolla
Andrea Paciolla
 
Maven TestNg frame work (1) (1)
Gopi Raghavendra
 
Grails unit testing
pleeps
 
Test Driven Development
Sheeju Alex
 
Ad

Viewers also liked (9)

PDF
Thales Smalltalk Usage: PicUnit
ESUG
 
PDF
A low Overhead Per Object Write Barrier for Smalltalk
ESUG
 
PDF
Lowcode: Extending Smalltalk with C Types to Improve Performance
ESUG
 
PDF
Power and Energy Code Profiling in Pharo
ESUG
 
PDF
Rolemodeling as a graphic extension of the Smalltalk IDE
ESUG
 
PDF
OpenPonk modeling platform
ESUG
 
PDF
New Native Windows UI possibilities in Cincom Smalltalk ObjectStudio
ESUG
 
PDF
Pragmas: Literal Messages as Powerful Method Annotations
ESUG
 
PDF
The Object Repository - Pulling Objects out of the Ecosystem
ESUG
 
Thales Smalltalk Usage: PicUnit
ESUG
 
A low Overhead Per Object Write Barrier for Smalltalk
ESUG
 
Lowcode: Extending Smalltalk with C Types to Improve Performance
ESUG
 
Power and Energy Code Profiling in Pharo
ESUG
 
Rolemodeling as a graphic extension of the Smalltalk IDE
ESUG
 
OpenPonk modeling platform
ESUG
 
New Native Windows UI possibilities in Cincom Smalltalk ObjectStudio
ESUG
 
Pragmas: Literal Messages as Powerful Method Annotations
ESUG
 
The Object Repository - Pulling Objects out of the Ecosystem
ESUG
 
Ad

Similar to Just in Time Resourcing (20)

PPTX
An Introduction to Unit Testing
Sahar Nofal
 
PDF
Test and Behaviour Driven Development (TDD/BDD)
Lars Thorup
 
PPTX
Unit Testing and TDD 2017
Xavi Hidalgo
 
PPT
Automated testing overview
Alex Pop
 
PDF
An Introduction to Unit Test Using NUnit
weili_at_slideshare
 
PPTX
Test Driven Development (TDD) - CVCC 2011
Tom Steele
 
PDF
Automated Testing with Ruby
Keith Pitty
 
PDF
Introduction to Automated Testing
Lars Thorup
 
PDF
Introduction to-automated-testing
BestBrains
 
PPTX
presentation des google test dans un contexte de tdd
Thierry Gayet
 
PPT
Google test training
Thierry Gayet
 
KEY
Javascript unit testing, yes we can e big
Andy Peterson
 
PPTX
Beginners overview of automated testing with Rspec
jeffrey1ross
 
PDF
Rspec
Amitai Barnea
 
PPTX
Skillwise Unit Testing
Skillwise Group
 
PPT
Unit Testing, TDD and the Walking Skeleton
Seb Rose
 
PPTX
Rc2010 tdd
JasonOffutt
 
PPTX
Test driven development
Nascenia IT
 
PPTX
Unit testing, UI testing and Test Driven Development in Visual Studio 2012
Jacinto Limjap
 
PDF
Introduction To UnitTesting & JUnit
Mindfire Solutions
 
An Introduction to Unit Testing
Sahar Nofal
 
Test and Behaviour Driven Development (TDD/BDD)
Lars Thorup
 
Unit Testing and TDD 2017
Xavi Hidalgo
 
Automated testing overview
Alex Pop
 
An Introduction to Unit Test Using NUnit
weili_at_slideshare
 
Test Driven Development (TDD) - CVCC 2011
Tom Steele
 
Automated Testing with Ruby
Keith Pitty
 
Introduction to Automated Testing
Lars Thorup
 
Introduction to-automated-testing
BestBrains
 
presentation des google test dans un contexte de tdd
Thierry Gayet
 
Google test training
Thierry Gayet
 
Javascript unit testing, yes we can e big
Andy Peterson
 
Beginners overview of automated testing with Rspec
jeffrey1ross
 
Skillwise Unit Testing
Skillwise Group
 
Unit Testing, TDD and the Walking Skeleton
Seb Rose
 
Rc2010 tdd
JasonOffutt
 
Test driven development
Nascenia IT
 
Unit testing, UI testing and Test Driven Development in Visual Studio 2012
Jacinto Limjap
 
Introduction To UnitTesting & JUnit
Mindfire Solutions
 

More from ESUG (20)

PDF
ShowUs: Pharo Stream Deck (ESUG 2025, Gdansk)
ESUG
 
PDF
Micromaid: A simple Mermaid-like chart generator for Pharo
ESUG
 
PDF
Directing Generative AI for Pharo Documentation
ESUG
 
PDF
Even Lighter Than Lightweiht: Augmenting Type Inference with Primitive Heuris...
ESUG
 
PDF
Integrating Executable Requirements in Prototyping
ESUG
 
PDF
Composing and Performing Electronic Music on-the-Fly with Pharo and Coypu
ESUG
 
PDF
Gamifying Agent-Based Models in Cormas: Towards the Playable Architecture for...
ESUG
 
PDF
Analysing Python Machine Learning Notebooks with Moose
ESUG
 
PDF
FASTTypeScript metamodel generation using FAST traits and TreeSitter project
ESUG
 
PDF
Migrating Katalon Studio Tests to Playwright with Model Driven Engineering
ESUG
 
PDF
Package-Aware Approach for Repository-Level Code Completion in Pharo
ESUG
 
PDF
Evaluating Benchmark Quality: a Mutation-Testing- Based Methodology
ESUG
 
PDF
An Analysis of Inline Method Refactoring
ESUG
 
PDF
Identification of unnecessary object allocations using static escape analysis
ESUG
 
PDF
Control flow-sensitive optimizations In the Druid Meta-Compiler
ESUG
 
PDF
Clean Blocks (IWST 2025, Gdansk, Poland)
ESUG
 
PDF
Encoding for Objects Matters (IWST 2025)
ESUG
 
PDF
Challenges of Transpiling Smalltalk to JavaScript
ESUG
 
PDF
Immersive experiences: what Pharo users do!
ESUG
 
PDF
ChatPharo: an Open Architecture for Understanding How to Talk Live to LLMs
ESUG
 
ShowUs: Pharo Stream Deck (ESUG 2025, Gdansk)
ESUG
 
Micromaid: A simple Mermaid-like chart generator for Pharo
ESUG
 
Directing Generative AI for Pharo Documentation
ESUG
 
Even Lighter Than Lightweiht: Augmenting Type Inference with Primitive Heuris...
ESUG
 
Integrating Executable Requirements in Prototyping
ESUG
 
Composing and Performing Electronic Music on-the-Fly with Pharo and Coypu
ESUG
 
Gamifying Agent-Based Models in Cormas: Towards the Playable Architecture for...
ESUG
 
Analysing Python Machine Learning Notebooks with Moose
ESUG
 
FASTTypeScript metamodel generation using FAST traits and TreeSitter project
ESUG
 
Migrating Katalon Studio Tests to Playwright with Model Driven Engineering
ESUG
 
Package-Aware Approach for Repository-Level Code Completion in Pharo
ESUG
 
Evaluating Benchmark Quality: a Mutation-Testing- Based Methodology
ESUG
 
An Analysis of Inline Method Refactoring
ESUG
 
Identification of unnecessary object allocations using static escape analysis
ESUG
 
Control flow-sensitive optimizations In the Druid Meta-Compiler
ESUG
 
Clean Blocks (IWST 2025, Gdansk, Poland)
ESUG
 
Encoding for Objects Matters (IWST 2025)
ESUG
 
Challenges of Transpiling Smalltalk to JavaScript
ESUG
 
Immersive experiences: what Pharo users do!
ESUG
 
ChatPharo: an Open Architecture for Understanding How to Talk Live to LLMs
ESUG
 

Recently uploaded (20)

PDF
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
PDF
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
PDF
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
 
PPTX
Agile Chennai 18-19 July 2025 Ideathon | AI Powered Microfinance Literacy Gui...
AgileNetwork
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PDF
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 
PDF
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
PDF
Research-Fundamentals-and-Topic-Development.pdf
ayesha butalia
 
PDF
How ETL Control Logic Keeps Your Pipelines Safe and Reliable.pdf
Stryv Solutions Pvt. Ltd.
 
PDF
GDG Cloud Munich - Intro - Luiz Carneiro - #BuildWithAI - July - Abdel.pdf
Luiz Carneiro
 
PDF
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
 
PDF
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
 
PDF
Responsible AI and AI Ethics - By Sylvester Ebhonu
Sylvester Ebhonu
 
PDF
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
PPTX
AI in Daily Life: How Artificial Intelligence Helps Us Every Day
vanshrpatil7
 
PPTX
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 
PDF
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
PDF
Economic Impact of Data Centres to the Malaysian Economy
flintglobalapac
 
PPTX
Agile Chennai 18-19 July 2025 | Emerging patterns in Agentic AI by Bharani Su...
AgileNetwork
 
PDF
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
 
Agile Chennai 18-19 July 2025 Ideathon | AI Powered Microfinance Literacy Gui...
AgileNetwork
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
Research-Fundamentals-and-Topic-Development.pdf
ayesha butalia
 
How ETL Control Logic Keeps Your Pipelines Safe and Reliable.pdf
Stryv Solutions Pvt. Ltd.
 
GDG Cloud Munich - Intro - Luiz Carneiro - #BuildWithAI - July - Abdel.pdf
Luiz Carneiro
 
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
 
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
 
Responsible AI and AI Ethics - By Sylvester Ebhonu
Sylvester Ebhonu
 
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
AI in Daily Life: How Artificial Intelligence Helps Us Every Day
vanshrpatil7
 
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
Economic Impact of Data Centres to the Malaysian Economy
flintglobalapac
 
Agile Chennai 18-19 July 2025 | Emerging patterns in Agentic AI by Bharani Su...
AgileNetwork
 
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 

Just in Time Resourcing

  • 1. ESUG – 1sep2009 - 0 Just-in-time Resourcing: fast tests in SUnit 3.2 and friends Niall Ross, Cincom 1 September 2009 Version 1.0 SUnit
  • 2. SUnit Once upon a time there were three classes ... TestCase TestSuite TestResult ... and then there was a fourth TestResource This talk is about: (mainly) TestResources in SUnit 3.2 (briefly) SUnit status
  • 3. TestResource is an optimisation Kent Beck’s rules of optimisation Rule 1: do it later Rule 2: see rule 1 eXtreme Programming practices Test-driven development “ But my tests are too slow.” Refactoring “ So refactor your tests to be fast.” enter TestResource and (somewhat later) explanations of it Make it run Make it right Make it fast
  • 4. Problems with TestResource XP style : “Do it later” / “You won’t need it”: Every resource set up before any test is run If one resource of one test in a suite of 15,000+ fails … … the run does nothing – not what you want to see when next you look XP Style : refactoring + “last make it fast” MyTestCase>>setUp … self assert: databaseSession isOnline description: ‘not online’. Tests getting slow? Refactor to a TestResource. MyTestResource(Object)>>doesNotUnderstand: #assert:description:
  • 5. Problems with TestResources Resources can compete with other resources: e.g. connect to one DB at a time, several DBs to test I coded the CompetingResource pattern: in SUnit 3.1 and earlier, not easy ! Stephane D and Martin K also had patterns – also not easy Resources can rely on other resources: Tests (and resources) can have ordered resources MyTestCase class>>resources ^Array wth: ConnectToDBResource with: AddTestDataToDBResource resource setUp (tearDown) not in order (reverse order) resource setUp / tearDown after resource that needs it
  • 6. What has changed in TestResource Resources are made available just-in-time: first test that needs it prompts set up later tests that need it see it has (or failed to) set up tearDown guaranteed at end of run; can be done anytime resetting in a test’s tearDown trades performance for test isolation Resources understand #assert:… protocol setUp and isAvailable run inside the handler in end-run tearDown, #assert: is just better protocol for same behaviour Resource-processing is ordered a test’s resources setUp in order and tearDown in reverse order a resource’s resources setUp before it and tearDown after it
  • 7. Code changes: just-in-time resourcing TestCase>>runCase self resources do: [:each | self assert: each isAvailable description: 'Unavailable resource ', each name, ' requested by test ', self printString]. [self setUp. self performTest] sunitEnsure: [self tearDown]. TestSuite>>run | result | result := TestResult new. self resources do: [ :each | each isAvailable ifFalse: [^each signalInitializationError]]. [self run: result] sunitEnsure: [self resources reverseDo : [:each | each reset]]. ^result
  • 8. Code changes: 3-valued logic for ‘current’ TestResource class>>isAvailable current isNil ifTrue: [ self makeAvailable ]. ^ self isAlreadyAvailable TestResource class>>makeAvailable | candidate | current := false. "any object not nil and not an instance of me would do" self resources do: [:each | self assert: each isAvailable description: 'Unavailable resource ', each name, ' requested by resource ', self name]. candidate := self new. candidate isAvailable ifTrue: [current := candidate]. TestResource class>>isAlreadyAvailable ^current class == self
  • 9. Class changes Once upon a time there were three classes ... TestCase, TestSuite and TestResult ... and then there was a fourth ... TestResource ... and now a fifth ... TestAsserter : abstract superclass of TestCase TestResource any user-created TestCase delegate class ( ... and that’s enough ! )
  • 10. Any impact on Users ? Logging TestCase methods moved to the class-side #isLogging, and #failureLog (and #logFailure: is on both sides) (So, who here overrides #isLogging or #failureLog ?) Profiling a test… method’s time: no impact a test suite’s overall time: no impact a test’s time in #runCase: sometimes see resource time time moved from start of suite’s #run to start of (some) tests’ #runCase Any objections, voice them now !
  • 11. SUnit 3.2 Make your tests run Make your tests right Make your tests fast (resources can help) Thanks to Yuri Mironenko, Dale Henrichs, James Foster, Tim MacKinnon for helping me port to Squeak, Gemstone and Dolphin.
  • 12. SUnit and Friends SUnit: cross-dialect, backward-compatible, 3-5 classes Add-ons: SUnitXProcPatterns, SUnitResourcePatterns, etc. UIs: RBSUnitExtensions SUnitBrowser, Squeak TestRunner, etc. SUnitToo: VW-specific, experimental, 11 classes SUnit-Bridge2SU2 maps SUnit tests to SUnitToo tests Assessments: VW-specific, configurable, 40+ classes transparent bridges configurable for SUnit, SUnitToo, etc. GemStone’s test framework … SUnit wants ideas SUnit will remain cross-dialect, backward-compatible, small

Editor's Notes

  • #2: 0 "Just-in-time resourcing:  fast, flexible testing with SUnit and friends", Niall Ross, Cincom In the beginning was basic SUnit:  just 3 classes.  Then a fourth, TestResource, was added, for use when your tests became slow.  However TestResource could create problems of its own and how to use it was not always clear.  Switching code from test to resource was not as easy as it could have been.  Niall will present the robust SUnit 3.2 implementation of resources, with examples. The talk will also cover some other SUnit topics - Basic SUnit did not handle tests that spawned subthreads.  Niall will briefly reprise his StS talk on the SUnit add-on that handles this - SUnit tools and variants have appeared:  Niall will look at some VW and VA tools, and how to combine using them with using basic SUnit.
  • #3: Once upon a time there was Ward Cunningham. When he pair-programmed with people, they were much more productive. Then there was Kent Beck – who wondered why this was. Then there were three classes – and a papar – and a name: Sunit And then the millenium came and suddenly there were four classes. Actually, it wasn’t very sudden.
  • #4: TestResource exists because test-driven development is only fast if your tests are fast. TestResource was deployed – and (rather later) explanations of how to use it were deployed. It was never a tricky pattern - it was in many ways a straightforward implementation of the singleton pattern, but it was just complex enough that people needed hints. Whereas some such implementations use a #defaultInstance or #current or whatever accessor and have users manipulate the singleton instance, TestResource>>current was mostly just expected to be called by the framework, while users simply referenced their TestResource subclasses, not those subclasses’ instances. This made a fair amount of sense – the intent I believe was to give users an easy and at the same time very safe (i.e. Minimal) interface – but the original Sunit Camp Smalltalk progenitors Jeff O’Dell and Joseph Pelrine and Sames were not in perfect unison on the point. In my refactoring of TestResource, I have been greatly helped by the fact that a many people have written ‘bad’ TestResource code – code that violates the pattern, that does things in bizarre and inefficient ways, etc., etc. When refactoring tests in a hurry, it was easy to guess wrong.
  • #5: One resource fails => nothing in suite runs. “ Do it later / You won’t need it” is an XP maxim, but every resource that any test in a suite needs is set up on starting, before any test is run. That might just be a point of style but the following is really annoying: - You finish work for the day. Last thing, you hit the overall run of 15,000 tests or whatever and go home. TestResources are by definition slow so their set up has not finished when you leave. Next morning, you gather that one resource failed and nothing was done. :-/ Make it fast last => refactor to resource but resource DNU self assert Competing resources: my system can connect to one database at a time, my tests run against specific databases, my overall suite wants to run all my tests, my database connections are test resources.
  • #6: Competing resources: my system can connect to one database at a time, my tests run against specific databases, my overall suite wants to run all my tests, my database connections are test resources.
  • #7: The original status was that a resource was set up once for the whole run, the best case scenario for performance but the worst case scenario for possible interaction between tests. In Sunit 3.2, this remains the default choice. If the coder makes their test reset a resource in some circumstance, they are choosing to sacrifice some performance in exchange for isolating other tests from theirs.
  • #8: The code that setUp all resources before the run starts, failing (and leaving the earlier ones setUp) if any could not be, is dropped . Instead, we add code so that each test asks whether its resources are available; as we shall see, this check is cost-free unless it is the first time of asking. As you can see from the deleted code, it used to be that only if all TestResources were set up would any of them be torn down. In 3.2, a resource that completes its own setUp and is available will be torn down even if another resource fails. This is still les rigorous than for tests: if a test enters setUp it will be torn down. Should we do the same for resources?
  • #9: The three-valued logic is that current is - nil : no setUp attempt has yet been made in this run - false : a setUp attempt was made but failed - an instance of the resource : a setUp attempt was made and succeeded
  • #10: Once upon a time there was Ward Cunningham. When he pair-programmed with people, they were much more productive. Then there was Kent Beck – who wondered why this was. Then there were three classes – and a papar – and a name: Sunit And then the millenium came and suddenly there were four classes. Actually, it wasn’t very sudden.
  • #11: The original status was that a resource was set up once for the whole run, the best case scenario for performance but the worst case scenario for possible interaction between tests. In Sunit 3.2, this remains the default choice. If the coder makes their test reset a resource in some circumstance, they are choosing to sacrifice some performance in exchange for isolating other tests from theirs.
  • #12: 6 Other changes: - fixes to ensure running single tests and debugging also calls resources. Put should:/shouldnt: into #deprecated protocol TestResource>>uninitialize / tearDown partners RestResource>>initialize / setUp More details package, class and method comments Things we did not change If a test enters setUp it wll be torn down. If a resource exits setUp and isAvailable, it will be torn down. Usd to be, if a resource failed, NIALL: MAKE CHANGE: - sunitVersion must return 3.2 not 3.1.1
  • #13: The original status was that a resource was set up once for the whole run, the best case scenario for performance but the worst case scenario for possible interaction between tests. In Sunit 3.2, this remains the default choice. If the coder makes their test reset a resource in some circumstance, they are choosing to sacrifice some performance in exchange for isolating other tests from theirs.