SlideShare a Scribd company logo
1 of 25
Download to read offline
Quality of Life
through Unit Testing
PyCon Malaysia 2015 Workshop
WHAT we wish to accomplish
today?
1. Understand Unit Test in improving quality of life
2. Practice Unit Testing using python 3
3. Integrate Unit Testing as part of workflow
Materials
GitHub https://github.com/kiawin/pyconmy2015
git clone git@github.com:kiawin/pyconmy2015.git
vagrant up
vagrant ssh
Sian Lerk Lau
linkedin.com/in/sianlerk
sianlerk.lau@onapp.com | kiawin@gmail.com
Software Engineer
Volunteer
Educator-in-Exile
https://twitter.com/OnApp - https://facebook.com/OnApp
1. Understand Unit Test in improving quality of life
Quality of Life
is determined by
Quality of Code
Quality of Life
(of one)
is determined by
(the)
Quality of Code
(that one wrote)
Quality of Life
(of one)
is determined by
(the)
Quality of Code
(that someone wrote)
WHAT is unit?
A unit of work is a single logical functional
use case in the system that can be invoked by
some public interface (in most cases). A unit
of work can span a single method, a whole
class or multiple classes working together to
achieve one single logical purpose that can
be verified.
- The Art of Unit Test, Roy Osherove
WHAT is a good unit test
● Able to be fully automated
● Has full control over all the pieces running (Use mocks
or stubs to achieve this isolation when needed)
● Can be run in any order if part of many other tests
● Runs in memory (no DB or File access, for example)
● Consistently returns the same result (You always run
the same test, so no random numbers, for example.
save those for integration or range tests)
● Runs fast
● Tests a single logical concept in the system
● Readable
● Maintainable
● Trustworthy (when you see its result, you don’t need to
debug the code just to be sure)
2. Practice Unit Testing using python 3
vagrant up
vagrant provision
vagrant ssh
cd /vagrant/src
# Module / Guide
https://docs.python.org/3.4/library/unittest.html#module-
unittest
http://docs.python-guide.org/en/latest/writing/tests/
2. Practice Unit Testing Trick #1 Doc-less Reference
vagrant@archlinux:/vagrant$ python
Python 3.4.3 (default, Mar 25 2015, 17:13:50)
[GCC 4.9.2 20150304 (prerelease)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import unittest
>>> dir(unittest)
['BaseTestSuite', 'FunctionTestCase', 'SkipTest', 'TestCase', 'TestLoader',
'TestProgram', 'TestResult', 'TestSuite', 'TextTestResult', 'TextTestRunner',
'_TextTestResult', '__all__', '__builtins__', '__cached__', '__doc__', '__file__',
'__loader__', '__name__', '__package__', '__path__', '__spec__', '__unittest',
'case', 'defaultTestLoader', 'expectedFailure', 'findTestCases',
'getTestCaseNames', 'installHandler', 'loader', 'main', 'makeSuite',
'registerResult', 'removeHandler', 'removeResult', 'result', 'runner', 'signals',
'skip', 'skipIf', 'skipUnless', 'suite', 'util']
2. Practice Unit Testing Trick #1 Doc-less Reference
vagrant@archlinux:/vagrant$ python
Python 3.4.3 (default, Mar 25 2015, 17:13:50)
[GCC 4.9.2 20150304 (prerelease)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import unittest
>>> dir(unittest.TestCase)
['__call__', '__class__', '__delattr__', '__dict__', '__dir__', '__doc__',
'__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__',
'__init__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__',
'__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__',
'__subclasshook__', '__weakref__', '_addExpectedFailure', '_addSkip',
'_addUnexpectedSuccess', '_baseAssertEqual', '_classSetupFailed', '_deprecate',
'_diffThreshold', '_feedErrorsToResult', '_formatMessage',
'_getAssertEqualityFunc', '_truncateMessage', 'addCleanup', 'addTypeEqualityFunc',
'assertAlmostEqual', 'assertAlmostEquals', 'assertCountEqual',
'assertDictContainsSubset', 'assertDictEqual', 'assertEqual', 'assertEquals',
'assertFalse', 'assertGreater', 'assertGreaterEqual', 'assertIn', 'assertIs',
'assertIsInstance', 'assertIsNone', 'assertIsNot', 'assertIsNotNone',
'assertLess', 'assertLessEqual', 'assertListEqual', 'assertLogs',
'assertMultiLineEqual', 'assertNotAlmostEqual', 'assertNotAlmostEquals',
'assertNotEqual', 'assertNotEquals', 'assertNotIn', 'assertNotIsInstance',
'assertNotRegex', 'assertRaises', 'assertRaisesRegex', 'assertRaisesRegexp',
2. Practice Unit Testing Trick #1 Doc-less Reference
vagrant@archlinux:/vagrant$ python
Python 3.4.3 (default, Mar 25 2015, 17:13:50)
[GCC 4.9.2 20150304 (prerelease)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import unittest
>>> import inspect
>>> inspect.getargspec(unittest.TestCase.assertEqual)
ArgSpec(args=['self', 'first', 'second', 'msg'], varargs=None, keywords=None,
defaults=(None,))
Ref: http://stackoverflow.com/questions/218616/getting-method-parameter-names-in-python
2. Practice Unit Testing Trick #2 Import Module
vagrant@archlinux:/vagrant/src$ python tests/calculator_tests.py
Traceback (most recent call last):
File "tests/calculator_tests.py", line 1, in <module>
import calculator
ImportError: No module named 'calculator'
# Solution - Set PYTHONPATH
PYTHONPATH=./ python tests/calculator_tests.py
Ref: http://stackoverflow.com/questions/5602559/where-is-the-python-path-set-when-i-dont-have-a-bash-profile
2. Practice Unit Testing Trick #3 Autorun Test
watch -n 2 "PYTHONPATH=./ python tests/calculator_tests.py"
Every 2.0s: PYTHONPATH=./ python tests/calculator_tests.py Thu Aug 20 13:02:39 2015
F
======================================================================
FAIL: test_add (__main__.TestCalculator)
----------------------------------------------------------------------
Traceback (most recent call last):
File "tests/calculator_tests.py", line 14, in test_add
self.assertEqual(c.add(1,2),2,"Alamak?")
AssertionError: 3 != 2 : Alamak?
----------------------------------------------------------------------
Ran 1 test in 0.002s
FAILED (failures=1)
2. Practice Unit Testing Trick #3 Autorun Test
watch -n 2 "PYTHONPATH=./ python tests/calculator_tests.py"
Every 2.0s: PYTHONPATH=./ python tests/calculator_tests.py Thu Aug 20 13:11:44 2015
.
----------------------------------------------------------------------
Ran 1 test in 0.000s
OK
2. Practice Unit Testing Examples
1. simple calculator
2. simple assertion
3. use setUp
4. use tearDown
5. mock / patch
3. Integrate Unit Testing as part of workflow
● Validate your work - Integration
● Part of development flow - TDD
Our Way
● Unit tests as part of development process
● Continuous integration using Jenkins
● Behavioral tests to perform functional,
integration and regression tests on
applications.
● Performance tests based on defined
metrics
We’re hiring!
● System Admins as integral role in managing and
develop tools for our ecosystem
● Software Developers as engineering role in
creating bleeding edge applications for our ecosystem
Wonderful things we use
Python, Java, Ruby, Lua, Nginx, Wowza, Puppet, Vagrant,
Docker, Debian, Cucumber, RabbitMQ, MariaDB,
MongoDB, ELK, etc.
Q&A

More Related Content

What's hot

Introduction to JUnit testing in OpenDaylight
Introduction to JUnit testing in OpenDaylightIntroduction to JUnit testing in OpenDaylight
Introduction to JUnit testing in OpenDaylightOpenDaylight
 
Automated Testing for Embedded Software in C or C++
Automated Testing for Embedded Software in C or C++Automated Testing for Embedded Software in C or C++
Automated Testing for Embedded Software in C or C++Lars Thorup
 
JUnit 5 - Evolution and Innovation - SpringOne Platform 2019
JUnit 5 - Evolution and Innovation - SpringOne Platform 2019JUnit 5 - Evolution and Innovation - SpringOne Platform 2019
JUnit 5 - Evolution and Innovation - SpringOne Platform 2019Sam Brannen
 
Google C++ Testing Framework in Visual Studio 2008
Google C++ Testing Framework in Visual Studio 2008Google C++ Testing Framework in Visual Studio 2008
Google C++ Testing Framework in Visual Studio 2008Andrea Francia
 
Unit testing on embedded target with C++Test
Unit testing on embedded  target with C++TestUnit testing on embedded  target with C++Test
Unit testing on embedded target with C++TestEngineering Software Lab
 
Junit4&testng presentation
Junit4&testng presentationJunit4&testng presentation
Junit4&testng presentationSanjib Dhar
 
Quickly Testing Qt Desktop Applications
Quickly Testing Qt Desktop ApplicationsQuickly Testing Qt Desktop Applications
Quickly Testing Qt Desktop ApplicationsClare Macrae
 
DIY in 5 Minutes: Testing Django App with Pytest
DIY in 5 Minutes: Testing Django App with Pytest DIY in 5 Minutes: Testing Django App with Pytest
DIY in 5 Minutes: Testing Django App with Pytest Inexture Solutions
 
Renaissance of JUnit - Introduction to JUnit 5
Renaissance of JUnit - Introduction to JUnit 5Renaissance of JUnit - Introduction to JUnit 5
Renaissance of JUnit - Introduction to JUnit 5Jimmy Lu
 
Google mock for dummies
Google mock for dummiesGoogle mock for dummies
Google mock for dummiesHarry Potter
 
Unit Test Your Database
Unit Test Your DatabaseUnit Test Your Database
Unit Test Your DatabaseDavid Wheeler
 
iOS Unit Testing
iOS Unit TestingiOS Unit Testing
iOS Unit Testingsgleadow
 
20111018 boost and gtest
20111018 boost and gtest20111018 boost and gtest
20111018 boost and gtestWill Shen
 
Automated testing in Python and beyond
Automated testing in Python and beyondAutomated testing in Python and beyond
Automated testing in Python and beyonddn
 
Qtp interview questions and answers
Qtp interview questions and answersQtp interview questions and answers
Qtp interview questions and answersITeLearn
 
AUTOMATED TESTING USING PYTHON (ATE)
AUTOMATED TESTING USING PYTHON (ATE)AUTOMATED TESTING USING PYTHON (ATE)
AUTOMATED TESTING USING PYTHON (ATE)Yuvaraja Ravi
 

What's hot (20)

Python unit testing
Python unit testingPython unit testing
Python unit testing
 
Introduction to JUnit testing in OpenDaylight
Introduction to JUnit testing in OpenDaylightIntroduction to JUnit testing in OpenDaylight
Introduction to JUnit testing in OpenDaylight
 
JUnit 5
JUnit 5JUnit 5
JUnit 5
 
Automated Testing for Embedded Software in C or C++
Automated Testing for Embedded Software in C or C++Automated Testing for Embedded Software in C or C++
Automated Testing for Embedded Software in C or C++
 
Doing the Impossible
Doing the ImpossibleDoing the Impossible
Doing the Impossible
 
Junit
JunitJunit
Junit
 
JUnit 5 - Evolution and Innovation - SpringOne Platform 2019
JUnit 5 - Evolution and Innovation - SpringOne Platform 2019JUnit 5 - Evolution and Innovation - SpringOne Platform 2019
JUnit 5 - Evolution and Innovation - SpringOne Platform 2019
 
Google C++ Testing Framework in Visual Studio 2008
Google C++ Testing Framework in Visual Studio 2008Google C++ Testing Framework in Visual Studio 2008
Google C++ Testing Framework in Visual Studio 2008
 
Unit testing on embedded target with C++Test
Unit testing on embedded  target with C++TestUnit testing on embedded  target with C++Test
Unit testing on embedded target with C++Test
 
Junit4&testng presentation
Junit4&testng presentationJunit4&testng presentation
Junit4&testng presentation
 
Quickly Testing Qt Desktop Applications
Quickly Testing Qt Desktop ApplicationsQuickly Testing Qt Desktop Applications
Quickly Testing Qt Desktop Applications
 
DIY in 5 Minutes: Testing Django App with Pytest
DIY in 5 Minutes: Testing Django App with Pytest DIY in 5 Minutes: Testing Django App with Pytest
DIY in 5 Minutes: Testing Django App with Pytest
 
Renaissance of JUnit - Introduction to JUnit 5
Renaissance of JUnit - Introduction to JUnit 5Renaissance of JUnit - Introduction to JUnit 5
Renaissance of JUnit - Introduction to JUnit 5
 
Google mock for dummies
Google mock for dummiesGoogle mock for dummies
Google mock for dummies
 
Unit Test Your Database
Unit Test Your DatabaseUnit Test Your Database
Unit Test Your Database
 
iOS Unit Testing
iOS Unit TestingiOS Unit Testing
iOS Unit Testing
 
20111018 boost and gtest
20111018 boost and gtest20111018 boost and gtest
20111018 boost and gtest
 
Automated testing in Python and beyond
Automated testing in Python and beyondAutomated testing in Python and beyond
Automated testing in Python and beyond
 
Qtp interview questions and answers
Qtp interview questions and answersQtp interview questions and answers
Qtp interview questions and answers
 
AUTOMATED TESTING USING PYTHON (ATE)
AUTOMATED TESTING USING PYTHON (ATE)AUTOMATED TESTING USING PYTHON (ATE)
AUTOMATED TESTING USING PYTHON (ATE)
 

Similar to Quality of life through Unit Testing

Testing Django Applications
Testing Django ApplicationsTesting Django Applications
Testing Django ApplicationsGareth Rushgrove
 
Making the most of your Test Suite
Making the most of your Test SuiteMaking the most of your Test Suite
Making the most of your Test Suiteericholscher
 
Effective testing with pytest
Effective testing with pytestEffective testing with pytest
Effective testing with pytestHector Canto
 
Dusan Lukic Magento 2 Integration Tests Meet Magento Serbia 2016
Dusan Lukic Magento 2 Integration Tests Meet Magento Serbia 2016Dusan Lukic Magento 2 Integration Tests Meet Magento Serbia 2016
Dusan Lukic Magento 2 Integration Tests Meet Magento Serbia 2016Dusan Lukic
 
PyCon AU 2012 - Debugging Live Python Web Applications
PyCon AU 2012 - Debugging Live Python Web ApplicationsPyCon AU 2012 - Debugging Live Python Web Applications
PyCon AU 2012 - Debugging Live Python Web ApplicationsGraham Dumpleton
 
Code igniter unittest-part1
Code igniter unittest-part1Code igniter unittest-part1
Code igniter unittest-part1Albert Rosa
 
Improve unit tests with Mutants!
Improve unit tests with Mutants!Improve unit tests with Mutants!
Improve unit tests with Mutants!Paco van Beckhoven
 
Rifartek Robot Training Course - How to use ClientRobot
Rifartek Robot Training Course - How to use ClientRobotRifartek Robot Training Course - How to use ClientRobot
Rifartek Robot Training Course - How to use ClientRobotTsai Tsung-Yi
 
Performance and Scalability Testing with Python and Multi-Mechanize
Performance and Scalability Testing with Python and Multi-MechanizePerformance and Scalability Testing with Python and Multi-Mechanize
Performance and Scalability Testing with Python and Multi-Mechanizecoreygoldberg
 
Testing of javacript
Testing of javacriptTesting of javacript
Testing of javacriptLei Kang
 
Getting Started with Test-Driven Development at Longhorn PHP 2023
Getting Started with Test-Driven Development at Longhorn PHP 2023Getting Started with Test-Driven Development at Longhorn PHP 2023
Getting Started with Test-Driven Development at Longhorn PHP 2023Scott Keck-Warren
 
JAVASCRIPT Test Driven Development & Jasmine
JAVASCRIPT Test Driven Development & JasmineJAVASCRIPT Test Driven Development & Jasmine
JAVASCRIPT Test Driven Development & JasmineAnup Singh
 
Qtp Basics
Qtp BasicsQtp Basics
Qtp Basicsmehramit
 
HP Quick Test Professional
HP Quick Test ProfessionalHP Quick Test Professional
HP Quick Test ProfessionalVitaliy Ganzha
 
Pemrograman Python untuk Pemula
Pemrograman Python untuk PemulaPemrograman Python untuk Pemula
Pemrograman Python untuk PemulaOon Arfiandwi
 
Simple tools to fight bigger quality battle
Simple tools to fight bigger quality battleSimple tools to fight bigger quality battle
Simple tools to fight bigger quality battleAnand Ramdeo
 
Comparative Development Methodologies
Comparative Development MethodologiesComparative Development Methodologies
Comparative Development Methodologieselliando dias
 
Open Source ERP Technologies for Java Developers
Open Source ERP Technologies for Java DevelopersOpen Source ERP Technologies for Java Developers
Open Source ERP Technologies for Java Developerscboecking
 
Automated Unit Testing
Automated Unit TestingAutomated Unit Testing
Automated Unit TestingMike Lively
 

Similar to Quality of life through Unit Testing (20)

Testing Django Applications
Testing Django ApplicationsTesting Django Applications
Testing Django Applications
 
Making the most of your Test Suite
Making the most of your Test SuiteMaking the most of your Test Suite
Making the most of your Test Suite
 
Effective testing with pytest
Effective testing with pytestEffective testing with pytest
Effective testing with pytest
 
Dusan Lukic Magento 2 Integration Tests Meet Magento Serbia 2016
Dusan Lukic Magento 2 Integration Tests Meet Magento Serbia 2016Dusan Lukic Magento 2 Integration Tests Meet Magento Serbia 2016
Dusan Lukic Magento 2 Integration Tests Meet Magento Serbia 2016
 
PyCon AU 2012 - Debugging Live Python Web Applications
PyCon AU 2012 - Debugging Live Python Web ApplicationsPyCon AU 2012 - Debugging Live Python Web Applications
PyCon AU 2012 - Debugging Live Python Web Applications
 
Code igniter unittest-part1
Code igniter unittest-part1Code igniter unittest-part1
Code igniter unittest-part1
 
Improve unit tests with Mutants!
Improve unit tests with Mutants!Improve unit tests with Mutants!
Improve unit tests with Mutants!
 
Rifartek Robot Training Course - How to use ClientRobot
Rifartek Robot Training Course - How to use ClientRobotRifartek Robot Training Course - How to use ClientRobot
Rifartek Robot Training Course - How to use ClientRobot
 
Performance and Scalability Testing with Python and Multi-Mechanize
Performance and Scalability Testing with Python and Multi-MechanizePerformance and Scalability Testing with Python and Multi-Mechanize
Performance and Scalability Testing with Python and Multi-Mechanize
 
Neutron Extension API
Neutron Extension APINeutron Extension API
Neutron Extension API
 
Testing of javacript
Testing of javacriptTesting of javacript
Testing of javacript
 
Getting Started with Test-Driven Development at Longhorn PHP 2023
Getting Started with Test-Driven Development at Longhorn PHP 2023Getting Started with Test-Driven Development at Longhorn PHP 2023
Getting Started with Test-Driven Development at Longhorn PHP 2023
 
JAVASCRIPT Test Driven Development & Jasmine
JAVASCRIPT Test Driven Development & JasmineJAVASCRIPT Test Driven Development & Jasmine
JAVASCRIPT Test Driven Development & Jasmine
 
Qtp Basics
Qtp BasicsQtp Basics
Qtp Basics
 
HP Quick Test Professional
HP Quick Test ProfessionalHP Quick Test Professional
HP Quick Test Professional
 
Pemrograman Python untuk Pemula
Pemrograman Python untuk PemulaPemrograman Python untuk Pemula
Pemrograman Python untuk Pemula
 
Simple tools to fight bigger quality battle
Simple tools to fight bigger quality battleSimple tools to fight bigger quality battle
Simple tools to fight bigger quality battle
 
Comparative Development Methodologies
Comparative Development MethodologiesComparative Development Methodologies
Comparative Development Methodologies
 
Open Source ERP Technologies for Java Developers
Open Source ERP Technologies for Java DevelopersOpen Source ERP Technologies for Java Developers
Open Source ERP Technologies for Java Developers
 
Automated Unit Testing
Automated Unit TestingAutomated Unit Testing
Automated Unit Testing
 

More from Sian Lerk Lau

Solving performance issues in Django ORM
Solving performance issues in Django ORMSolving performance issues in Django ORM
Solving performance issues in Django ORMSian Lerk Lau
 
The journey of an (un)orthodox optimization
The journey of an (un)orthodox optimizationThe journey of an (un)orthodox optimization
The journey of an (un)orthodox optimizationSian Lerk Lau
 
Velocity. Agility. Python. (Pycon APAC 2017)
Velocity. Agility. Python. (Pycon APAC 2017)Velocity. Agility. Python. (Pycon APAC 2017)
Velocity. Agility. Python. (Pycon APAC 2017)Sian Lerk Lau
 
DevOps - Myth or Real
DevOps - Myth or RealDevOps - Myth or Real
DevOps - Myth or RealSian Lerk Lau
 
Learning python with flask (PyLadies Malaysia 2017 Workshop #1)
Learning python with flask (PyLadies Malaysia 2017 Workshop #1)Learning python with flask (PyLadies Malaysia 2017 Workshop #1)
Learning python with flask (PyLadies Malaysia 2017 Workshop #1)Sian Lerk Lau
 
Install Archlinux in 10 Steps (Sort of) :)
Install Archlinux in 10 Steps (Sort of) :)Install Archlinux in 10 Steps (Sort of) :)
Install Archlinux in 10 Steps (Sort of) :)Sian Lerk Lau
 

More from Sian Lerk Lau (7)

Solving performance issues in Django ORM
Solving performance issues in Django ORMSolving performance issues in Django ORM
Solving performance issues in Django ORM
 
The journey of an (un)orthodox optimization
The journey of an (un)orthodox optimizationThe journey of an (un)orthodox optimization
The journey of an (un)orthodox optimization
 
Velocity. Agility. Python. (Pycon APAC 2017)
Velocity. Agility. Python. (Pycon APAC 2017)Velocity. Agility. Python. (Pycon APAC 2017)
Velocity. Agility. Python. (Pycon APAC 2017)
 
DevOps - Myth or Real
DevOps - Myth or RealDevOps - Myth or Real
DevOps - Myth or Real
 
Learning python with flask (PyLadies Malaysia 2017 Workshop #1)
Learning python with flask (PyLadies Malaysia 2017 Workshop #1)Learning python with flask (PyLadies Malaysia 2017 Workshop #1)
Learning python with flask (PyLadies Malaysia 2017 Workshop #1)
 
Python and you
Python and youPython and you
Python and you
 
Install Archlinux in 10 Steps (Sort of) :)
Install Archlinux in 10 Steps (Sort of) :)Install Archlinux in 10 Steps (Sort of) :)
Install Archlinux in 10 Steps (Sort of) :)
 

Recently uploaded

Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024The Digital Insurer
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024The Digital Insurer
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistandanishmna97
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 

Recently uploaded (20)

Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 

Quality of life through Unit Testing

  • 1. Quality of Life through Unit Testing PyCon Malaysia 2015 Workshop
  • 2. WHAT we wish to accomplish today? 1. Understand Unit Test in improving quality of life 2. Practice Unit Testing using python 3 3. Integrate Unit Testing as part of workflow
  • 3. Materials GitHub https://github.com/kiawin/pyconmy2015 git clone git@github.com:kiawin/pyconmy2015.git vagrant up vagrant ssh
  • 4. Sian Lerk Lau linkedin.com/in/sianlerk sianlerk.lau@onapp.com | kiawin@gmail.com Software Engineer Volunteer Educator-in-Exile
  • 5.
  • 7.
  • 8. 1. Understand Unit Test in improving quality of life
  • 9. Quality of Life is determined by Quality of Code
  • 10. Quality of Life (of one) is determined by (the) Quality of Code (that one wrote)
  • 11. Quality of Life (of one) is determined by (the) Quality of Code (that someone wrote)
  • 12. WHAT is unit? A unit of work is a single logical functional use case in the system that can be invoked by some public interface (in most cases). A unit of work can span a single method, a whole class or multiple classes working together to achieve one single logical purpose that can be verified. - The Art of Unit Test, Roy Osherove
  • 13. WHAT is a good unit test ● Able to be fully automated ● Has full control over all the pieces running (Use mocks or stubs to achieve this isolation when needed) ● Can be run in any order if part of many other tests ● Runs in memory (no DB or File access, for example) ● Consistently returns the same result (You always run the same test, so no random numbers, for example. save those for integration or range tests) ● Runs fast ● Tests a single logical concept in the system ● Readable ● Maintainable ● Trustworthy (when you see its result, you don’t need to debug the code just to be sure)
  • 14. 2. Practice Unit Testing using python 3 vagrant up vagrant provision vagrant ssh cd /vagrant/src # Module / Guide https://docs.python.org/3.4/library/unittest.html#module- unittest http://docs.python-guide.org/en/latest/writing/tests/
  • 15. 2. Practice Unit Testing Trick #1 Doc-less Reference vagrant@archlinux:/vagrant$ python Python 3.4.3 (default, Mar 25 2015, 17:13:50) [GCC 4.9.2 20150304 (prerelease)] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import unittest >>> dir(unittest) ['BaseTestSuite', 'FunctionTestCase', 'SkipTest', 'TestCase', 'TestLoader', 'TestProgram', 'TestResult', 'TestSuite', 'TextTestResult', 'TextTestRunner', '_TextTestResult', '__all__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', '__unittest', 'case', 'defaultTestLoader', 'expectedFailure', 'findTestCases', 'getTestCaseNames', 'installHandler', 'loader', 'main', 'makeSuite', 'registerResult', 'removeHandler', 'removeResult', 'result', 'runner', 'signals', 'skip', 'skipIf', 'skipUnless', 'suite', 'util']
  • 16. 2. Practice Unit Testing Trick #1 Doc-less Reference vagrant@archlinux:/vagrant$ python Python 3.4.3 (default, Mar 25 2015, 17:13:50) [GCC 4.9.2 20150304 (prerelease)] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import unittest >>> dir(unittest.TestCase) ['__call__', '__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_addExpectedFailure', '_addSkip', '_addUnexpectedSuccess', '_baseAssertEqual', '_classSetupFailed', '_deprecate', '_diffThreshold', '_feedErrorsToResult', '_formatMessage', '_getAssertEqualityFunc', '_truncateMessage', 'addCleanup', 'addTypeEqualityFunc', 'assertAlmostEqual', 'assertAlmostEquals', 'assertCountEqual', 'assertDictContainsSubset', 'assertDictEqual', 'assertEqual', 'assertEquals', 'assertFalse', 'assertGreater', 'assertGreaterEqual', 'assertIn', 'assertIs', 'assertIsInstance', 'assertIsNone', 'assertIsNot', 'assertIsNotNone', 'assertLess', 'assertLessEqual', 'assertListEqual', 'assertLogs', 'assertMultiLineEqual', 'assertNotAlmostEqual', 'assertNotAlmostEquals', 'assertNotEqual', 'assertNotEquals', 'assertNotIn', 'assertNotIsInstance', 'assertNotRegex', 'assertRaises', 'assertRaisesRegex', 'assertRaisesRegexp',
  • 17. 2. Practice Unit Testing Trick #1 Doc-less Reference vagrant@archlinux:/vagrant$ python Python 3.4.3 (default, Mar 25 2015, 17:13:50) [GCC 4.9.2 20150304 (prerelease)] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import unittest >>> import inspect >>> inspect.getargspec(unittest.TestCase.assertEqual) ArgSpec(args=['self', 'first', 'second', 'msg'], varargs=None, keywords=None, defaults=(None,)) Ref: http://stackoverflow.com/questions/218616/getting-method-parameter-names-in-python
  • 18. 2. Practice Unit Testing Trick #2 Import Module vagrant@archlinux:/vagrant/src$ python tests/calculator_tests.py Traceback (most recent call last): File "tests/calculator_tests.py", line 1, in <module> import calculator ImportError: No module named 'calculator' # Solution - Set PYTHONPATH PYTHONPATH=./ python tests/calculator_tests.py Ref: http://stackoverflow.com/questions/5602559/where-is-the-python-path-set-when-i-dont-have-a-bash-profile
  • 19. 2. Practice Unit Testing Trick #3 Autorun Test watch -n 2 "PYTHONPATH=./ python tests/calculator_tests.py" Every 2.0s: PYTHONPATH=./ python tests/calculator_tests.py Thu Aug 20 13:02:39 2015 F ====================================================================== FAIL: test_add (__main__.TestCalculator) ---------------------------------------------------------------------- Traceback (most recent call last): File "tests/calculator_tests.py", line 14, in test_add self.assertEqual(c.add(1,2),2,"Alamak?") AssertionError: 3 != 2 : Alamak? ---------------------------------------------------------------------- Ran 1 test in 0.002s FAILED (failures=1)
  • 20. 2. Practice Unit Testing Trick #3 Autorun Test watch -n 2 "PYTHONPATH=./ python tests/calculator_tests.py" Every 2.0s: PYTHONPATH=./ python tests/calculator_tests.py Thu Aug 20 13:11:44 2015 . ---------------------------------------------------------------------- Ran 1 test in 0.000s OK
  • 21. 2. Practice Unit Testing Examples 1. simple calculator 2. simple assertion 3. use setUp 4. use tearDown 5. mock / patch
  • 22. 3. Integrate Unit Testing as part of workflow ● Validate your work - Integration ● Part of development flow - TDD
  • 23. Our Way ● Unit tests as part of development process ● Continuous integration using Jenkins ● Behavioral tests to perform functional, integration and regression tests on applications. ● Performance tests based on defined metrics
  • 24. We’re hiring! ● System Admins as integral role in managing and develop tools for our ecosystem ● Software Developers as engineering role in creating bleeding edge applications for our ecosystem Wonderful things we use Python, Java, Ruby, Lua, Nginx, Wowza, Puppet, Vagrant, Docker, Debian, Cucumber, RabbitMQ, MariaDB, MongoDB, ELK, etc.
  • 25. Q&A