SlideShare a Scribd company logo
Automated Software Testing
Arild Nilsen, May 2016
• Introduction
• Dependency Injection
• Tips & Tricks
automated software testing
test-driven development (TDD)
vs.
software tester
vs.
integration test
unit test system test
acceptance test
end-to-end test
A/B test
Should you write tests?
- Truth about booking.com
“Booking is destroying my career (…)
I am not allowed to write tests”
“I don’t do tests”
- David Thomas
A/B testing
Some unit tests
Very experienced
Writes tests for complex algorithm
Benefits of automated tests
• Catch regression errors
• Drives the design of the code
• Serves as documentation
Dependency Injection
class Poller:
def __init__(self):
self.service = Service()
def wait_for_completed(self):
while not self.service.is_done():
sleep(10)
Poller().wait_for_completed()
class Poller:
def __init__(self, service, poll_delay):
self.service = service
self.poll_delay = poll_delay
def wait_for_completed(self):
while not self.service.is_done():
sleep(self.poll_delay)
Poller(Service(), 10).wait_for_completed()
class Poller:
def set_service(self, service):
self.service = service
def set_poll_delay(self, poll_delay):
self.poll_delay = poll_delay
def wait_for_completed(self):
while not self.service.is_done():
sleep(self.poll_delay)
poller = Poller()
poller.set_service(Service())
poller.set_poll_delay(10)
poller.wait_for_completed()
Testing with mocks
class ServiceMock(Service):
def __init__(self):
self.called = 0
def is_done(self):
self.called += 1
return self.called == 2
def terminates_when_service_is_done():
mock = ServiceMock()
Poller(mock, 0).wait_for_completed()
assert 2 is mock.called
def terminates_when_service_is_done():
mock = Mock(Service)
when(mock.is_done())
.thenReturn(False)
.thenReturn(True)
Poller(mock, 0).wait_for_completed()
verify(mock, times(2)).is_done()
Composition vs Inheritance
class Poller(Service):
def __init__(self, poll_delay):
self.poll_delay = poll_delay
def wait_for_completed(self):
while not self.is_done():
sleep(self.poll_delay)
class PollerTest(Poller):
def __init__(self, poll_delay):
super(PollerTest,self)
.__init__(poll_delay)
self.called = 0
def is_done(self):
self.called += 1
return self.called == 2
def terminates_when_service_is_done():
poller = PollerTest(poll_delay=0)
poller.wait_for_completed()
assert 2 is poller.called
Things that makes testing
harder
• Inheritance
• Static methods
• Global state
• Mixing of concerns
• Top 10 things which make your code hard to
test
Tips & Tricks
See the test fail
• Does it actually fail?
• Is the error message descriptive?
@Test
public void readsFile() throws VodFileStorageException {
try (InputStream stream = new InputStream("clip.mp4")) {
ftpFileStorage.writeFile("tmp.mp4", stream);
}
try (InputStream expected = new InputStream("clip.mp4"))) {
InputStream actual = ftpFileStorage.readFile("tmp.mp4");
contentEquals(expected, actual);
}
}
@Test
public void readsFile() throws VodFileStorageException {
try (InputStream stream = new InputStream("clip.mp4")) {
ftpFileStorage.writeFile("tmp.mp4", stream);
}
try (InputStream expected = new InputStream("clip.mp4"))) {
InputStream actual = ftpFileStorage.readFile("tmp.mp4");
assertThat(contentEquals(expected, actual), is(true));
}
}
Naming and structuring tests
• Test features over methods
• Some duplication is fine, but test should read
well
@Mock
FolderWatchService service;
@Test
public void addsJobId() throws Exception {
FolderWatch folderWatch = createFolderWatch()
.jobIds(newHashSet())
.build();
JobId id1 = createJob().build().getId();
JobId id2 = createJob().build().getId();
folderWatch.addJobId(service, id1);
verify(service).addJobId(folderWatch.getId(), id1);
assertThat(folderWatch.getJobIds(), is(newHashSet(id1)));
folderWatch.addJobId(service, id2);
verify(service).addJobId(folderWatch.getId(), id2);
assertThat(folderWatch.getJobIds(), is(newHashSet(id1, id2)));
}
Scope of test
Writing Great Unit Tests:
Best and Worst Practice
- Steve Sanderson, 2009
Testing too much
• And’s , Or’s or But’s
• Too many mocks
Where to learn more?
Inversion of Control Containers
and the Dependency Injection
pattern
- Martin Fowler, 2004
Writing Great Unit Tests:
Best and Worst Practice
- Steve Sanderson, 2009

More Related Content

PDF
Automated testing
Aiste Stikliute
 
PDF
How To Use Selenium Successfully
Dave Haeffner
 
PDF
Mock Introduction
Tim (文昌)
 
PPTX
Automated tests to a REST API
Luís Barros Nóbrega
 
PPTX
REST API testing with SpecFlow
Aiste Stikliute
 
PPTX
Api testing
Keshav Kashyap
 
PDF
HowOthersDoAutomatedTesting
George Jeffcock
 
PDF
Web API Test Automation using Frisby & Node.js
Chi Lang Le Vu Tran
 
Automated testing
Aiste Stikliute
 
How To Use Selenium Successfully
Dave Haeffner
 
Mock Introduction
Tim (文昌)
 
Automated tests to a REST API
Luís Barros Nóbrega
 
REST API testing with SpecFlow
Aiste Stikliute
 
Api testing
Keshav Kashyap
 
HowOthersDoAutomatedTesting
George Jeffcock
 
Web API Test Automation using Frisby & Node.js
Chi Lang Le Vu Tran
 

What's hot (20)

PDF
How to Use Selenium, Successfully
Sauce Labs
 
PDF
Mastering UI automation at Scale: Key Lessons and Best Practices (By Fernando...
Applitools
 
PPTX
API Testing with Frisby and Mocha
Lyudmila Anisimova
 
PPTX
B4USolution_API-Testing
b4usolution .
 
PDF
Selenium Best Practices with Jason Huggins
Sauce Labs
 
PPTX
Angular Unit Test
Michael Haberman
 
PDF
Validation for APIs in Laravel 4
Kirk Bushell
 
PDF
Diffy : Automatic Testing of Microservices @ Twitter
Puneet Khanduri
 
PDF
API Testing: The heart of functional testing" with Bj Rollison
TEST Huddle
 
PDF
Integration testing - A&BP CC
JWORKS powered by Ordina
 
PPTX
API Test Automation Using Karate (Anil Kumar Moka)
Peter Thomas
 
PDF
Unit testing in Force.com platform
Chamil Madusanka
 
PPTX
Automation is Easy! (python version)
Iakiv Kramarenko
 
PDF
Unit-testing and E2E testing in JS
Michael Haberman
 
PDF
Selenium Tips & Tricks, presented at the Tel Aviv Selenium Meetup
Dave Haeffner
 
PPTX
A Beginer's Guide to testing in Django
Psalms Kalu
 
PDF
Mastering Test Automation: How to Use Selenium Successfully
Applitools
 
PPTX
Automated Acceptance Tests & Tool choice
toddbr
 
PDF
Codeception
Jonathan Lau
 
How to Use Selenium, Successfully
Sauce Labs
 
Mastering UI automation at Scale: Key Lessons and Best Practices (By Fernando...
Applitools
 
API Testing with Frisby and Mocha
Lyudmila Anisimova
 
B4USolution_API-Testing
b4usolution .
 
Selenium Best Practices with Jason Huggins
Sauce Labs
 
Angular Unit Test
Michael Haberman
 
Validation for APIs in Laravel 4
Kirk Bushell
 
Diffy : Automatic Testing of Microservices @ Twitter
Puneet Khanduri
 
API Testing: The heart of functional testing" with Bj Rollison
TEST Huddle
 
Integration testing - A&BP CC
JWORKS powered by Ordina
 
API Test Automation Using Karate (Anil Kumar Moka)
Peter Thomas
 
Unit testing in Force.com platform
Chamil Madusanka
 
Automation is Easy! (python version)
Iakiv Kramarenko
 
Unit-testing and E2E testing in JS
Michael Haberman
 
Selenium Tips & Tricks, presented at the Tel Aviv Selenium Meetup
Dave Haeffner
 
A Beginer's Guide to testing in Django
Psalms Kalu
 
Mastering Test Automation: How to Use Selenium Successfully
Applitools
 
Automated Acceptance Tests & Tool choice
toddbr
 
Codeception
Jonathan Lau
 
Ad

Viewers also liked (20)

PPTX
Orientation Program on Automated Software testing Powered by Infaum Education...
Anju ML
 
PPT
Automated testing vs manual testing
Neha Polke
 
PDF
The Debate: Manual vs Automated Testing
DeRisk IT Inc.
 
PPT
Software Quality Assurance(Sqa) automated software testing
REHMAT ULLAH
 
PDF
Software Testing Process, Testing Automation and Software Testing Trends
KMS Technology
 
PPT
Automated Testing vs Manual Testing
Directi Group
 
PPTX
日本の中小企業のIT導入10年の振り返り
Yuichi Morito
 
PPS
"My Way"
Umberto Pacheco
 
PDF
Binary RDF for Scalable Publishing, Exchanging and Consumption in the Web of ...
WU (Vienna University of Economics and Business)
 
PDF
Cantinart
Dániel Wéber
 
PDF
2014 dart flight school in Tokyo
nothingcosmos
 
PPTX
Skepsis congres 2015 - Het begrip deskundigheid - Frans van Lunteren
Maarten Koller
 
PDF
Wassup! July 2011 issue - the Cultural Trends magazine
Ogilvy & Mather Asia Pacific
 
PDF
18200111 681400421-f oes05-2012
maricarmenrodriguez
 
PPTX
Wildlife manager
hashimhashim
 
PPTX
Inatherm Company Profile
willemsikkers
 
PDF
PVK 17062011
Narasimha Sharma
 
PPT
Offline Patients Quarterly Newsletter
Graham Atherton
 
PDF
Една хубава история
George Alex
 
PPTX
list of english words of ......... origin
87honey
 
Orientation Program on Automated Software testing Powered by Infaum Education...
Anju ML
 
Automated testing vs manual testing
Neha Polke
 
The Debate: Manual vs Automated Testing
DeRisk IT Inc.
 
Software Quality Assurance(Sqa) automated software testing
REHMAT ULLAH
 
Software Testing Process, Testing Automation and Software Testing Trends
KMS Technology
 
Automated Testing vs Manual Testing
Directi Group
 
日本の中小企業のIT導入10年の振り返り
Yuichi Morito
 
"My Way"
Umberto Pacheco
 
Binary RDF for Scalable Publishing, Exchanging and Consumption in the Web of ...
WU (Vienna University of Economics and Business)
 
Cantinart
Dániel Wéber
 
2014 dart flight school in Tokyo
nothingcosmos
 
Skepsis congres 2015 - Het begrip deskundigheid - Frans van Lunteren
Maarten Koller
 
Wassup! July 2011 issue - the Cultural Trends magazine
Ogilvy & Mather Asia Pacific
 
18200111 681400421-f oes05-2012
maricarmenrodriguez
 
Wildlife manager
hashimhashim
 
Inatherm Company Profile
willemsikkers
 
PVK 17062011
Narasimha Sharma
 
Offline Patients Quarterly Newsletter
Graham Atherton
 
Една хубава история
George Alex
 
list of english words of ......... origin
87honey
 
Ad

Similar to Automated Software Testing (20)

PPTX
Test-Driven Development
John Blum
 
PDF
Unit testing basic
Yuri Anischenko
 
PDF
Deliver Faster with BDD/TDD - Designing Automated Tests That Don't Suck
Kevin Brockhoff
 
PDF
Getting Started With Testing
Giovanni Scerra ☃
 
PDF
Design for Testability
Stefano Dalla Palma
 
PPTX
Testing 101
Noam Barkai
 
PPT
Unit Testing
Ciprian Mester
 
PDF
Unit Testing and role of Test doubles
Ritesh Mehrotra
 
PPTX
Test Driven Development - a Practitioner’s Perspective
Malinda Kapuruge
 
PPTX
Test-Driven Design Insights@DevoxxBE 2023.pptx
Victor Rentea
 
PPTX
Anatomy of Test Driven Development
Dhaval Shah
 
PDF
Developer Test - Things to Know
vilniusjug
 
PPT
Integration testing
Tsegabrehan Am
 
PPTX
Unit Testing in Swift
GlobalLogic Ukraine
 
PDF
16 things a developer should know about testing
WolfSchlegel
 
PDF
The Art of Unit Testing Feedback
Deon Huang
 
PDF
Unit Testing
Scott Leberknight
 
PDF
Unit testing - A&BP CC
JWORKS powered by Ordina
 
PDF
Test and Behaviour Driven Development (TDD/BDD)
Lars Thorup
 
PDF
The Evolution of Software Testing_ Trends and Innovations.pdf
brijeshdeep4798
 
Test-Driven Development
John Blum
 
Unit testing basic
Yuri Anischenko
 
Deliver Faster with BDD/TDD - Designing Automated Tests That Don't Suck
Kevin Brockhoff
 
Getting Started With Testing
Giovanni Scerra ☃
 
Design for Testability
Stefano Dalla Palma
 
Testing 101
Noam Barkai
 
Unit Testing
Ciprian Mester
 
Unit Testing and role of Test doubles
Ritesh Mehrotra
 
Test Driven Development - a Practitioner’s Perspective
Malinda Kapuruge
 
Test-Driven Design Insights@DevoxxBE 2023.pptx
Victor Rentea
 
Anatomy of Test Driven Development
Dhaval Shah
 
Developer Test - Things to Know
vilniusjug
 
Integration testing
Tsegabrehan Am
 
Unit Testing in Swift
GlobalLogic Ukraine
 
16 things a developer should know about testing
WolfSchlegel
 
The Art of Unit Testing Feedback
Deon Huang
 
Unit Testing
Scott Leberknight
 
Unit testing - A&BP CC
JWORKS powered by Ordina
 
Test and Behaviour Driven Development (TDD/BDD)
Lars Thorup
 
The Evolution of Software Testing_ Trends and Innovations.pdf
brijeshdeep4798
 

Recently uploaded (20)

PDF
New Download MiniTool Partition Wizard Crack Latest Version 2025
imang66g
 
PPTX
Odoo Integration Services by Candidroot Solutions
CandidRoot Solutions Private Limited
 
PPT
Why Reliable Server Maintenance Service in New York is Crucial for Your Business
Sam Vohra
 
PDF
49785682629390197565_LRN3014_Migrating_the_Beast.pdf
Abilash868456
 
PDF
MiniTool Power Data Recovery Crack New Pre Activated Version Latest 2025
imang66g
 
PPTX
slidesgo-unlocking-the-code-the-dynamic-dance-of-variables-and-constants-2024...
kr2589474
 
PDF
Bandai Playdia The Book - David Glotz
BluePanther6
 
PPTX
AI-Ready Handoff: Auto-Summaries & Draft Emails from MQL to Slack in One Flow
bbedford2
 
PPTX
classification of computer and basic part of digital computer
ravisinghrajpurohit3
 
PDF
Immersive experiences: what Pharo users do!
ESUG
 
PDF
lesson-2-rules-of-netiquette.pdf.bshhsjdj
jasmenrojas249
 
PDF
Protecting the Digital World Cyber Securit
dnthakkar16
 
PDF
Using licensed Data Loss Prevention (DLP) as a strategic proactive data secur...
Q-Advise
 
PPTX
ConcordeApp: Engineering Global Impact & Unlocking Billions in Event ROI with AI
chastechaste14
 
PDF
New Download FL Studio Crack Full Version [Latest 2025]
imang66g
 
PDF
Key Features to Look for in Arizona App Development Services
Net-Craft.com
 
PDF
An Experience-Based Look at AI Lead Generation Pricing, Features & B2B Results
Thomas albart
 
PDF
Generating Union types w/ Static Analysis
K. Matthew Dupree
 
PPTX
Web Testing.pptx528278vshbuqffqhhqiwnwuq
studylike474
 
PPTX
Presentation about variables and constant.pptx
kr2589474
 
New Download MiniTool Partition Wizard Crack Latest Version 2025
imang66g
 
Odoo Integration Services by Candidroot Solutions
CandidRoot Solutions Private Limited
 
Why Reliable Server Maintenance Service in New York is Crucial for Your Business
Sam Vohra
 
49785682629390197565_LRN3014_Migrating_the_Beast.pdf
Abilash868456
 
MiniTool Power Data Recovery Crack New Pre Activated Version Latest 2025
imang66g
 
slidesgo-unlocking-the-code-the-dynamic-dance-of-variables-and-constants-2024...
kr2589474
 
Bandai Playdia The Book - David Glotz
BluePanther6
 
AI-Ready Handoff: Auto-Summaries & Draft Emails from MQL to Slack in One Flow
bbedford2
 
classification of computer and basic part of digital computer
ravisinghrajpurohit3
 
Immersive experiences: what Pharo users do!
ESUG
 
lesson-2-rules-of-netiquette.pdf.bshhsjdj
jasmenrojas249
 
Protecting the Digital World Cyber Securit
dnthakkar16
 
Using licensed Data Loss Prevention (DLP) as a strategic proactive data secur...
Q-Advise
 
ConcordeApp: Engineering Global Impact & Unlocking Billions in Event ROI with AI
chastechaste14
 
New Download FL Studio Crack Full Version [Latest 2025]
imang66g
 
Key Features to Look for in Arizona App Development Services
Net-Craft.com
 
An Experience-Based Look at AI Lead Generation Pricing, Features & B2B Results
Thomas albart
 
Generating Union types w/ Static Analysis
K. Matthew Dupree
 
Web Testing.pptx528278vshbuqffqhhqiwnwuq
studylike474
 
Presentation about variables and constant.pptx
kr2589474
 

Automated Software Testing

  • 2. • Introduction • Dependency Injection • Tips & Tricks
  • 3. automated software testing test-driven development (TDD) vs. software tester vs.
  • 4. integration test unit test system test acceptance test end-to-end test A/B test
  • 5. Should you write tests? - Truth about booking.com “Booking is destroying my career (…) I am not allowed to write tests” “I don’t do tests” - David Thomas A/B testing Some unit tests Very experienced Writes tests for complex algorithm
  • 6. Benefits of automated tests • Catch regression errors • Drives the design of the code • Serves as documentation
  • 8. class Poller: def __init__(self): self.service = Service() def wait_for_completed(self): while not self.service.is_done(): sleep(10) Poller().wait_for_completed()
  • 9. class Poller: def __init__(self, service, poll_delay): self.service = service self.poll_delay = poll_delay def wait_for_completed(self): while not self.service.is_done(): sleep(self.poll_delay) Poller(Service(), 10).wait_for_completed()
  • 10. class Poller: def set_service(self, service): self.service = service def set_poll_delay(self, poll_delay): self.poll_delay = poll_delay def wait_for_completed(self): while not self.service.is_done(): sleep(self.poll_delay) poller = Poller() poller.set_service(Service()) poller.set_poll_delay(10) poller.wait_for_completed()
  • 12. class ServiceMock(Service): def __init__(self): self.called = 0 def is_done(self): self.called += 1 return self.called == 2 def terminates_when_service_is_done(): mock = ServiceMock() Poller(mock, 0).wait_for_completed() assert 2 is mock.called
  • 13. def terminates_when_service_is_done(): mock = Mock(Service) when(mock.is_done()) .thenReturn(False) .thenReturn(True) Poller(mock, 0).wait_for_completed() verify(mock, times(2)).is_done()
  • 15. class Poller(Service): def __init__(self, poll_delay): self.poll_delay = poll_delay def wait_for_completed(self): while not self.is_done(): sleep(self.poll_delay)
  • 16. class PollerTest(Poller): def __init__(self, poll_delay): super(PollerTest,self) .__init__(poll_delay) self.called = 0 def is_done(self): self.called += 1 return self.called == 2 def terminates_when_service_is_done(): poller = PollerTest(poll_delay=0) poller.wait_for_completed() assert 2 is poller.called
  • 17. Things that makes testing harder • Inheritance • Static methods • Global state • Mixing of concerns • Top 10 things which make your code hard to test
  • 19. See the test fail • Does it actually fail? • Is the error message descriptive?
  • 20. @Test public void readsFile() throws VodFileStorageException { try (InputStream stream = new InputStream("clip.mp4")) { ftpFileStorage.writeFile("tmp.mp4", stream); } try (InputStream expected = new InputStream("clip.mp4"))) { InputStream actual = ftpFileStorage.readFile("tmp.mp4"); contentEquals(expected, actual); } } @Test public void readsFile() throws VodFileStorageException { try (InputStream stream = new InputStream("clip.mp4")) { ftpFileStorage.writeFile("tmp.mp4", stream); } try (InputStream expected = new InputStream("clip.mp4"))) { InputStream actual = ftpFileStorage.readFile("tmp.mp4"); assertThat(contentEquals(expected, actual), is(true)); } }
  • 21. Naming and structuring tests • Test features over methods • Some duplication is fine, but test should read well
  • 22. @Mock FolderWatchService service; @Test public void addsJobId() throws Exception { FolderWatch folderWatch = createFolderWatch() .jobIds(newHashSet()) .build(); JobId id1 = createJob().build().getId(); JobId id2 = createJob().build().getId(); folderWatch.addJobId(service, id1); verify(service).addJobId(folderWatch.getId(), id1); assertThat(folderWatch.getJobIds(), is(newHashSet(id1))); folderWatch.addJobId(service, id2); verify(service).addJobId(folderWatch.getId(), id2); assertThat(folderWatch.getJobIds(), is(newHashSet(id1, id2))); }
  • 23. Scope of test Writing Great Unit Tests: Best and Worst Practice - Steve Sanderson, 2009
  • 24. Testing too much • And’s , Or’s or But’s • Too many mocks
  • 25. Where to learn more? Inversion of Control Containers and the Dependency Injection pattern - Martin Fowler, 2004 Writing Great Unit Tests: Best and Worst Practice - Steve Sanderson, 2009