SlideShare a Scribd company logo
Deon Huang 2018/1/19
The Art of UnitTesting
Agenda
✤ Overview
✤ Concept
✤ Core Techniques
✤ Practical tool in Java
✤ FAQ
✤ Conclusion
✤ Reference
Overview
What is test?
Let’s suppose you are dating a girl
✤ A good girl
✤ For a movie
✤ Don’t mess up
✤ Again, don’t mess up
What could possibly went wrong?
✤ Wallet?
✤ Movie ticket?
✤ Brush teeth?
✤ Umbrella?
✤ Traffic?
How to prevent
✤ Wallet?

- Check before
✤ Movie ticket?

- Check before
✤ Brush teeth?

- Do it before
✤ Umbrella?

- Check before
✤ Traffic?

- Best arrive early.
What’s the Pattern
✤ Wallet?

- Check before
✤ Movie ticket?

- Check before
✤ Brush teeth?

- Do it before
✤ Umbrella?

- Check before
✤ Traffic?

- Best arrive early.
Unit Test

Pattern?
Integration Test

Pattern?
What is an unit?
✤ Automation
✤ Not temporary
✤ Even your cat can press a button to launch and pass
✤ Fast
✤ Idempotent
✤ Independent
✤ Easy to present error cause
What is an unit?
✤ Automation : Press a button to finish
✤ Not temporary : Should live for reasonable long
✤ Even your cat can press a button to launch and pass
✤ Fast : Relatively faster than integration test
✤ Idempotent : Same result
✤ Independent : No dependence on other component state
✤ Easy to present error cause : Easy to debug
Why unit test is important
Motivations
✤ Update application without breaking things
✤ Validate functionality of updates
✤ Be able to trust deployment checks (CI/CD workflow)
✤ Confirm that refactoring didn’t break things
✤ Make software robust
✤ Easy to refactor
✤ Easy to debug
Test result
SoftwareTesting Scope
✤ The box approach

- White-box testing

- Black-Box testing
✤ Some important testing

- Stress Test

- Destructive Test

- Functional Test

- Beta Test
The Art of
UnitTesting
✤ Guides you step by step from
writing your first simple tests
to developing robust test sets
that are maintainable,
readable, and trustworthy.
Overview Recap
What is test?
What is this book about?
Concept
What is unit test?
What you expected from your program?
What is Unit Test doing?
Questions to Ask for UnitTest
✤ Let’s define Unit Test:
✤ Does unit test wrote two weeks ago still execute success and
get out come?
✤ Can my teammates pass my unit test wrote two month ago?
✤ Can unit tests finish in several minutes?
✤ One button to executes all unit test?
✤ Can I wrote basic unit test in minutes?
IntegrationTest
✤ Definition: Test against a working unit that isn’t full
controlled, might depends on real world component,
like time, network, database…

Definition of Good UnitTest
✤ Automation program that validates a method or a class
behavior.
✤ Writing on automation testing framework
✤ Easy to write
✤ Execute fast
✤ Same results for any user
✤ Act as green light save zone for developers
UnitTest vs IntegrationTest
✤ Scenario : Logger is an object that writes log to remote
database
✤ Unit Test: (Test-inhibiting)

Build up fake Logger

Assert object method output or called

Runs in isolation environment without external
dependency
✤ Integration Test:

Verify log built and written, log content validation
UnitTest Structure : 3A
✤ Arrange : Setup objects, configuration
✤ Act : Operate objects
✤ Assert : Assert an expected result
UnitTest Structure : 3A
Arrange
Act
Assert
NiFiPropertiesTest.java
Concept Recap
What is unit test
What is integration test
CoreTechniques
What are the skills or pattern?
Test Double
SUT : (System Under Test)

Whatever we are testing, 

Ex: Class, Method.
DOC : (Depended-On Component)

Component that SUT depends
Dummy Object
✤ Dummy : not going to be used, normally use for
passing compiler check.
✤ public void addAttendee(Human human)

public void Count(){}
Fake Object
✤ Fake : Fake object to avoid external dependency.
Simplify implementation for test purpose.
✤ @Override

public sendAlert(String message){

localFile.write(message);

}
Stub
✤ Stub:

For replacing a method with code that returns a
specified result
Mock
✤ Mock:

A stub with an expectations that the method gets called.
Stub vs Mock
✤ Unit has 3 possible result:

- Return value

- State change

- Interaction with dependency object
✤ Interaction Test:

Test how an object interact with other object

Should always be consider as last solution
Stub pattern
Mock Pattern
Stub vs Mock
✤ Stub Object:

Normally support object, this kind of test help verify
tested object. 

It won’t cause failure.
✤ Mock Object:

Normally main tested object, this kind of test might
cause failure
Stub pattern
Mock Pattern
Key Point of Good UnitTest
✤ Unit Test Tips —> Pre-knowledge
✤ Unit Test Best Practice —> Pattern
✤ Unit Test Code Smell —> Real Case
UnitTestTips
✤ Smallest unit of testing, trustable, repeatable
✤ Completely separate from integration test
✤ No contact of external resources or static object
✤ It’s not suggest writing unit test on DAL, (Data Access
Layer), associate with database.
✤ TrustWorthy
✤ Maintainable
✤ Readability
Three Success Key Factor
of UnitTest
UnitTest Best Practice
✤ Basic concept for Unit Test:
✤ TrustWorthy
✤ Maintainable
✤ Readability
✤ Trustworthy : 

- Can you trust your test result?

- Main purpose is finding test failure root cause
UnitTest Best Practice
✤ Maintainable : 

- Continuous maintain test code

- Lower cost of maintaining code
✤ Readability :

- Naming of unit test name

- If it’s hard to understand, people tend to not 

use, trust, maintain tests.
UnitTest Best Practice
Trustworthiness
NiFiPropertiesTest.java
Readability
Maintainable : Testable Design Pattern
UnitTest Code Smell
✤ No association of each test method
✤ No execution order of each test method
✤ Don’t assert two things in one test method
✤ Test method naming suggestion:

- Method name

- Scenario

- ExpectResult

ChangePassword_Get_ReturnViewResult
Practical tool in Java
Mockito, PowerMock
How can UnitTest Framework help
you
✤ Easy to write structured testing

- Tag of specific trait of unit test

- Provide method to assert result
✤ Execute unit test

- Found tests

- Automatically execute them

- Show progress
✤ Validate result

- Failed reason

- Failed, success counts
Isolation framework
✤ Why use isolation framework

Generate dynamic stub and mock at runtime.
✤ Benefits:

Easy to validate parameter

Easy to verify methods call count

Easy to build up fake object
Constrained Isolation Framework
✤ What is constrained isolation framework?

Constrained to mock some methods.

Ex: static method, non-public methods.
✤ Constrained Isolation framework build mock object by
override or extends base class and thus constrained to
compiler and Intermedia Language (IL)
Mockito
Mockito
TestJdbcCommon.java
PowerMock
✤ 介紹Concept & open source example
FAQ
Questions everyone encounter
FAQ
✤ Difference between Stub and Mock

http://williamherry.com/blog/2013/05/13/understand-stub-and-mock/
✤ Unit Test vs Integration Test

https://www.guru99.com/unit-test-vs-integration-test.html
✤ Unit Test pattern

http://xunitpatterns.com/index.html
✤ Unit Test Principle

https://github.com/ghsukumar/SFDC_Best_Practices/wiki/F.I.R.S.T-
Principles-of-Unit-Testing

Author Recommended
✤ Unit Test Pattern:

XUnit Test Pattern: Refactoring Test
✤ Legacy Code:

Working Effectively with Legacy Code
✤ CI/CD:

Continuous Integration: Improving Software Quality
and Reducing Risk
Conclusion
What’s the outcome for this hour?
Conclusion
✤ Unit Test vs Integration Test
✤ Test Double
✤ Key Point of Unit Test
✤ Three Success Key Factor of Unit Test
✤ Isolation framework
✤ FAQ
Reference
Other relative material
How many kinds
of testing term?
✤ https://www.utest.com/articles/
8-best-software-testing-books-qa-
engineer--tester-must-read
✤ Wiki : Software testing

https://en.wikipedia.org/wiki/
Software_testing
✤ Types of Software Testing

http://
www.softwaretestinghelp.com/
types-of-software-testing/
Reference
✤ Mockito

https://github.com/mockito/mockito/wiki
✤ PowerMock

https://github.com/powermock/powermock
Reference
✤ Notes of The Art of Unit Testing

https://blog.miniasp.com/post/2010/02/21/The-Art-of-
Unit-Testing-with-Roy-Osherove-Notes.aspx
✤ https://www.guru99.com/unit-test-vs-integration-test.html
✤ Good slides from docker

https://www.slideshare.net/rheinwein/stop-being-lazy-
and-test-your-software?
qid=2256a3e5-0099-40be-9a8e-6114ceec068b&v=&b=&from_s
earch=5
Reference
✤ 5 test double type

http://oomusou.io/jasmine/jasmine-test-double/
✤ XUnit Test Patterns

http://xunitpatterns.com/index.html
✤ Testing tutorial

https://www.tutorialspoint.com/software_testing

More Related Content

What's hot

Unit Test + Functional Programming = Love
Unit Test + Functional Programming = LoveUnit Test + Functional Programming = Love
Unit Test + Functional Programming = Love
Alvaro Videla
 
Acceptance And Story Testing Patterns - By Charles Bradley
Acceptance And Story Testing Patterns - By Charles BradleyAcceptance And Story Testing Patterns - By Charles Bradley
Acceptance And Story Testing Patterns - By Charles Bradley
Synerzip
 
Unit Testing Done Right
Unit Testing Done RightUnit Testing Done Right
Unit Testing Done Right
Brian Fenton
 
Test automation – the bitter truth
Test automation – the bitter truthTest automation – the bitter truth
Test automation – the bitter truth
Viktor Slavchev
 
Worst practices in software testing by the Testing troll
Worst practices in software testing by the Testing trollWorst practices in software testing by the Testing troll
Worst practices in software testing by the Testing troll
Viktor Slavchev
 
Unit Testing
Unit TestingUnit Testing
Unit Testing
Avinash Kadam
 
Automated Unit Testing
Automated Unit TestingAutomated Unit Testing
Automated Unit Testing
Mike Lively
 
Roy Osherove on Unit Testing Good Practices and Horrible Mistakes
Roy Osherove on Unit Testing Good Practices and Horrible MistakesRoy Osherove on Unit Testing Good Practices and Horrible Mistakes
Roy Osherove on Unit Testing Good Practices and Horrible MistakesRoy Osherove
 
Clean Unit Test Patterns
Clean Unit Test PatternsClean Unit Test Patterns
Clean Unit Test Patterns
Frank Appel
 
An Introduction to Unit Testing
An Introduction to Unit TestingAn Introduction to Unit Testing
An Introduction to Unit Testing
Joe Tremblay
 
Functional test best practice
Functional test best practiceFunctional test best practice
Functional test best practice
Test Armada
 
An insight to test driven development and unit testing
An insight to test driven development and unit testingAn insight to test driven development and unit testing
An insight to test driven development and unit testing
Dharmendra Prasad
 
Java Unit Test and Coverage Introduction
Java Unit Test and Coverage IntroductionJava Unit Test and Coverage Introduction
Java Unit Test and Coverage IntroductionAlex Su
 
Unit Testing Fundamentals
Unit Testing FundamentalsUnit Testing Fundamentals
Unit Testing FundamentalsRichard Paul
 
Automated tests
Automated testsAutomated tests
Automated tests
Damian Sromek
 
Creating testing tools to support development
Creating testing tools to support developmentCreating testing tools to support development
Creating testing tools to support development
Chema del Barco
 
Unit Testing Concepts and Best Practices
Unit Testing Concepts and Best PracticesUnit Testing Concepts and Best Practices
Unit Testing Concepts and Best Practices
Derek Smith
 
Workshop unit test
Workshop   unit testWorkshop   unit test
Workshop unit test
Francesco Garavaglia
 
Automation vs. intelligence - "follow me if you want to live"
Automation vs. intelligence - "follow me if you want to live"Automation vs. intelligence - "follow me if you want to live"
Automation vs. intelligence - "follow me if you want to live"
Viktor Slavchev
 

What's hot (20)

Unit Test + Functional Programming = Love
Unit Test + Functional Programming = LoveUnit Test + Functional Programming = Love
Unit Test + Functional Programming = Love
 
Acceptance And Story Testing Patterns - By Charles Bradley
Acceptance And Story Testing Patterns - By Charles BradleyAcceptance And Story Testing Patterns - By Charles Bradley
Acceptance And Story Testing Patterns - By Charles Bradley
 
Unit Testing Done Right
Unit Testing Done RightUnit Testing Done Right
Unit Testing Done Right
 
Test automation – the bitter truth
Test automation – the bitter truthTest automation – the bitter truth
Test automation – the bitter truth
 
Worst practices in software testing by the Testing troll
Worst practices in software testing by the Testing trollWorst practices in software testing by the Testing troll
Worst practices in software testing by the Testing troll
 
Unit Testing
Unit TestingUnit Testing
Unit Testing
 
Automated Unit Testing
Automated Unit TestingAutomated Unit Testing
Automated Unit Testing
 
Exploratory test
Exploratory testExploratory test
Exploratory test
 
Roy Osherove on Unit Testing Good Practices and Horrible Mistakes
Roy Osherove on Unit Testing Good Practices and Horrible MistakesRoy Osherove on Unit Testing Good Practices and Horrible Mistakes
Roy Osherove on Unit Testing Good Practices and Horrible Mistakes
 
Clean Unit Test Patterns
Clean Unit Test PatternsClean Unit Test Patterns
Clean Unit Test Patterns
 
An Introduction to Unit Testing
An Introduction to Unit TestingAn Introduction to Unit Testing
An Introduction to Unit Testing
 
Functional test best practice
Functional test best practiceFunctional test best practice
Functional test best practice
 
An insight to test driven development and unit testing
An insight to test driven development and unit testingAn insight to test driven development and unit testing
An insight to test driven development and unit testing
 
Java Unit Test and Coverage Introduction
Java Unit Test and Coverage IntroductionJava Unit Test and Coverage Introduction
Java Unit Test and Coverage Introduction
 
Unit Testing Fundamentals
Unit Testing FundamentalsUnit Testing Fundamentals
Unit Testing Fundamentals
 
Automated tests
Automated testsAutomated tests
Automated tests
 
Creating testing tools to support development
Creating testing tools to support developmentCreating testing tools to support development
Creating testing tools to support development
 
Unit Testing Concepts and Best Practices
Unit Testing Concepts and Best PracticesUnit Testing Concepts and Best Practices
Unit Testing Concepts and Best Practices
 
Workshop unit test
Workshop   unit testWorkshop   unit test
Workshop unit test
 
Automation vs. intelligence - "follow me if you want to live"
Automation vs. intelligence - "follow me if you want to live"Automation vs. intelligence - "follow me if you want to live"
Automation vs. intelligence - "follow me if you want to live"
 

Similar to The Art of Unit Testing Feedback

Unit testing
Unit testingUnit testing
Unit testing
PiXeL16
 
assertYourself - Breaking the Theories and Assumptions of Unit Testing in Flex
assertYourself - Breaking the Theories and Assumptions of Unit Testing in FlexassertYourself - Breaking the Theories and Assumptions of Unit Testing in Flex
assertYourself - Breaking the Theories and Assumptions of Unit Testing in Flex
michael.labriola
 
Test automation expert days
Test automation   expert daysTest automation   expert days
Test automation expert daysOren Rubin
 
Unit Testing and TDD 2017
Unit Testing and TDD 2017Unit Testing and TDD 2017
Unit Testing and TDD 2017
Xavi Hidalgo
 
Why Unit Testingl
Why Unit TestinglWhy Unit Testingl
Why Unit Testingl
priya_trivedi
 
Why unit testingl
Why unit testinglWhy unit testingl
Why unit testingl
Priya Sharma
 
Why Unit Testingl
Why Unit TestinglWhy Unit Testingl
Why Unit Testingl
priya_trivedi
 
Unit testing
Unit testingUnit testing
Unit testing
Panos Pnevmatikatos
 
Unit testing - An introduction
Unit testing - An introductionUnit testing - An introduction
Unit testing - An introduction
Alejandro Claro Mosqueda
 
Unit Testing
Unit TestingUnit Testing
Unit Testing
Anuj Arora
 
Software Testing
Software TestingSoftware Testing
Software Testing
AdroitLogic
 
Why Your Selenium Tests are so Dang Brittle, and What to Do About It
Why Your Selenium Tests are so Dang Brittle, and What to Do About ItWhy Your Selenium Tests are so Dang Brittle, and What to Do About It
Why Your Selenium Tests are so Dang Brittle, and What to Do About It
Jay Aho
 
Assessing Unit Test Quality
Assessing Unit Test QualityAssessing Unit Test Quality
Assessing Unit Test Qualityguest268ee8
 
Unit test documentation
Unit test documentationUnit test documentation
Unit test documentation
Anjan Debnath
 
An Introduction to unit testing
An Introduction to unit testingAn Introduction to unit testing
An Introduction to unit testingSteven Casey
 
Unit Testing
Unit TestingUnit Testing
Unit Testing
David Rogers
 
Making the Unstable Stable - An Intro To Testing
Making the Unstable Stable - An Intro To TestingMaking the Unstable Stable - An Intro To Testing
Making the Unstable Stable - An Intro To Testing
Cameron Presley
 
Ui Testing with Ghost Inspector
Ui Testing with Ghost InspectorUi Testing with Ghost Inspector
Ui Testing with Ghost Inspector
Harvard Web Working Group
 
Writing Tests with the Unity Test Framework
Writing Tests with the Unity Test FrameworkWriting Tests with the Unity Test Framework
Writing Tests with the Unity Test Framework
Peter Kofler
 

Similar to The Art of Unit Testing Feedback (20)

Unit testing
Unit testingUnit testing
Unit testing
 
assertYourself - Breaking the Theories and Assumptions of Unit Testing in Flex
assertYourself - Breaking the Theories and Assumptions of Unit Testing in FlexassertYourself - Breaking the Theories and Assumptions of Unit Testing in Flex
assertYourself - Breaking the Theories and Assumptions of Unit Testing in Flex
 
Test automation expert days
Test automation   expert daysTest automation   expert days
Test automation expert days
 
Unit Testing and TDD 2017
Unit Testing and TDD 2017Unit Testing and TDD 2017
Unit Testing and TDD 2017
 
Why Unit Testingl
Why Unit TestinglWhy Unit Testingl
Why Unit Testingl
 
Why unit testingl
Why unit testinglWhy unit testingl
Why unit testingl
 
Why Unit Testingl
Why Unit TestinglWhy Unit Testingl
Why Unit Testingl
 
Unit testing
Unit testingUnit testing
Unit testing
 
Unit testing - An introduction
Unit testing - An introductionUnit testing - An introduction
Unit testing - An introduction
 
Unit Testing
Unit TestingUnit Testing
Unit Testing
 
Software Testing
Software TestingSoftware Testing
Software Testing
 
Why Your Selenium Tests are so Dang Brittle, and What to Do About It
Why Your Selenium Tests are so Dang Brittle, and What to Do About ItWhy Your Selenium Tests are so Dang Brittle, and What to Do About It
Why Your Selenium Tests are so Dang Brittle, and What to Do About It
 
Assessing Unit Test Quality
Assessing Unit Test QualityAssessing Unit Test Quality
Assessing Unit Test Quality
 
Unit test documentation
Unit test documentationUnit test documentation
Unit test documentation
 
Unit testing, principles
Unit testing, principlesUnit testing, principles
Unit testing, principles
 
An Introduction to unit testing
An Introduction to unit testingAn Introduction to unit testing
An Introduction to unit testing
 
Unit Testing
Unit TestingUnit Testing
Unit Testing
 
Making the Unstable Stable - An Intro To Testing
Making the Unstable Stable - An Intro To TestingMaking the Unstable Stable - An Intro To Testing
Making the Unstable Stable - An Intro To Testing
 
Ui Testing with Ghost Inspector
Ui Testing with Ghost InspectorUi Testing with Ghost Inspector
Ui Testing with Ghost Inspector
 
Writing Tests with the Unity Test Framework
Writing Tests with the Unity Test FrameworkWriting Tests with the Unity Test Framework
Writing Tests with the Unity Test Framework
 

Recently uploaded

Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
XfilesPro
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
Adele Miller
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
IES VE
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Globus
 
RISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent EnterpriseRISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent Enterprise
Srikant77
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
Globus
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns
 
Graphic Design Crash Course for beginners
Graphic Design Crash Course for beginnersGraphic Design Crash Course for beginners
Graphic Design Crash Course for beginners
e20449
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
takuyayamamoto1800
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
wottaspaceseo
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdf
Ortus Solutions, Corp
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
Donna Lenk
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
WSO2
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
Fermin Galan
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
Globus
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Natan Silnitsky
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
Tendenci - The Open Source AMS (Association Management Software)
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
Cyanic lab
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
informapgpstrackings
 

Recently uploaded (20)

Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
 
RISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent EnterpriseRISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent Enterprise
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
 
Graphic Design Crash Course for beginners
Graphic Design Crash Course for beginnersGraphic Design Crash Course for beginners
Graphic Design Crash Course for beginners
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdf
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
 

The Art of Unit Testing Feedback

  • 1. Deon Huang 2018/1/19 The Art of UnitTesting
  • 2. Agenda ✤ Overview ✤ Concept ✤ Core Techniques ✤ Practical tool in Java ✤ FAQ ✤ Conclusion ✤ Reference
  • 4. Let’s suppose you are dating a girl ✤ A good girl ✤ For a movie ✤ Don’t mess up ✤ Again, don’t mess up
  • 5. What could possibly went wrong? ✤ Wallet? ✤ Movie ticket? ✤ Brush teeth? ✤ Umbrella? ✤ Traffic?
  • 6. How to prevent ✤ Wallet?
 - Check before ✤ Movie ticket?
 - Check before ✤ Brush teeth?
 - Do it before ✤ Umbrella?
 - Check before ✤ Traffic?
 - Best arrive early.
  • 7. What’s the Pattern ✤ Wallet?
 - Check before ✤ Movie ticket?
 - Check before ✤ Brush teeth?
 - Do it before ✤ Umbrella?
 - Check before ✤ Traffic?
 - Best arrive early. Unit Test
 Pattern? Integration Test
 Pattern?
  • 8. What is an unit? ✤ Automation ✤ Not temporary ✤ Even your cat can press a button to launch and pass ✤ Fast ✤ Idempotent ✤ Independent ✤ Easy to present error cause
  • 9. What is an unit? ✤ Automation : Press a button to finish ✤ Not temporary : Should live for reasonable long ✤ Even your cat can press a button to launch and pass ✤ Fast : Relatively faster than integration test ✤ Idempotent : Same result ✤ Independent : No dependence on other component state ✤ Easy to present error cause : Easy to debug
  • 10. Why unit test is important
  • 11. Motivations ✤ Update application without breaking things ✤ Validate functionality of updates ✤ Be able to trust deployment checks (CI/CD workflow) ✤ Confirm that refactoring didn’t break things
  • 12. ✤ Make software robust ✤ Easy to refactor ✤ Easy to debug Test result
  • 13. SoftwareTesting Scope ✤ The box approach
 - White-box testing
 - Black-Box testing ✤ Some important testing
 - Stress Test
 - Destructive Test
 - Functional Test
 - Beta Test
  • 14. The Art of UnitTesting ✤ Guides you step by step from writing your first simple tests to developing robust test sets that are maintainable, readable, and trustworthy.
  • 15. Overview Recap What is test? What is this book about?
  • 17. What you expected from your program? What is Unit Test doing?
  • 18. Questions to Ask for UnitTest ✤ Let’s define Unit Test: ✤ Does unit test wrote two weeks ago still execute success and get out come? ✤ Can my teammates pass my unit test wrote two month ago? ✤ Can unit tests finish in several minutes? ✤ One button to executes all unit test? ✤ Can I wrote basic unit test in minutes?
  • 19. IntegrationTest ✤ Definition: Test against a working unit that isn’t full controlled, might depends on real world component, like time, network, database…

  • 20. Definition of Good UnitTest ✤ Automation program that validates a method or a class behavior. ✤ Writing on automation testing framework ✤ Easy to write ✤ Execute fast ✤ Same results for any user ✤ Act as green light save zone for developers
  • 21. UnitTest vs IntegrationTest ✤ Scenario : Logger is an object that writes log to remote database ✤ Unit Test: (Test-inhibiting)
 Build up fake Logger
 Assert object method output or called
 Runs in isolation environment without external dependency ✤ Integration Test:
 Verify log built and written, log content validation
  • 22.
  • 23. UnitTest Structure : 3A ✤ Arrange : Setup objects, configuration ✤ Act : Operate objects ✤ Assert : Assert an expected result
  • 24. UnitTest Structure : 3A Arrange Act Assert NiFiPropertiesTest.java
  • 25. Concept Recap What is unit test What is integration test
  • 26. CoreTechniques What are the skills or pattern?
  • 27. Test Double SUT : (System Under Test)
 Whatever we are testing, 
 Ex: Class, Method. DOC : (Depended-On Component)
 Component that SUT depends
  • 28. Dummy Object ✤ Dummy : not going to be used, normally use for passing compiler check. ✤ public void addAttendee(Human human)
 public void Count(){}
  • 29. Fake Object ✤ Fake : Fake object to avoid external dependency. Simplify implementation for test purpose. ✤ @Override
 public sendAlert(String message){
 localFile.write(message);
 }
  • 30. Stub ✤ Stub:
 For replacing a method with code that returns a specified result
  • 31. Mock ✤ Mock:
 A stub with an expectations that the method gets called.
  • 32. Stub vs Mock ✤ Unit has 3 possible result:
 - Return value
 - State change
 - Interaction with dependency object ✤ Interaction Test:
 Test how an object interact with other object
 Should always be consider as last solution Stub pattern Mock Pattern
  • 33. Stub vs Mock ✤ Stub Object:
 Normally support object, this kind of test help verify tested object. 
 It won’t cause failure. ✤ Mock Object:
 Normally main tested object, this kind of test might cause failure Stub pattern Mock Pattern
  • 34. Key Point of Good UnitTest ✤ Unit Test Tips —> Pre-knowledge ✤ Unit Test Best Practice —> Pattern ✤ Unit Test Code Smell —> Real Case
  • 35. UnitTestTips ✤ Smallest unit of testing, trustable, repeatable ✤ Completely separate from integration test ✤ No contact of external resources or static object ✤ It’s not suggest writing unit test on DAL, (Data Access Layer), associate with database.
  • 36. ✤ TrustWorthy ✤ Maintainable ✤ Readability Three Success Key Factor of UnitTest
  • 37. UnitTest Best Practice ✤ Basic concept for Unit Test: ✤ TrustWorthy ✤ Maintainable ✤ Readability ✤ Trustworthy : 
 - Can you trust your test result?
 - Main purpose is finding test failure root cause
  • 38. UnitTest Best Practice ✤ Maintainable : 
 - Continuous maintain test code
 - Lower cost of maintaining code ✤ Readability :
 - Naming of unit test name
 - If it’s hard to understand, people tend to not 
 use, trust, maintain tests.
  • 40. UnitTest Code Smell ✤ No association of each test method ✤ No execution order of each test method ✤ Don’t assert two things in one test method ✤ Test method naming suggestion:
 - Method name
 - Scenario
 - ExpectResult
 ChangePassword_Get_ReturnViewResult
  • 41. Practical tool in Java Mockito, PowerMock
  • 42. How can UnitTest Framework help you ✤ Easy to write structured testing
 - Tag of specific trait of unit test
 - Provide method to assert result ✤ Execute unit test
 - Found tests
 - Automatically execute them
 - Show progress ✤ Validate result
 - Failed reason
 - Failed, success counts
  • 43. Isolation framework ✤ Why use isolation framework
 Generate dynamic stub and mock at runtime. ✤ Benefits:
 Easy to validate parameter
 Easy to verify methods call count
 Easy to build up fake object
  • 44. Constrained Isolation Framework ✤ What is constrained isolation framework?
 Constrained to mock some methods.
 Ex: static method, non-public methods. ✤ Constrained Isolation framework build mock object by override or extends base class and thus constrained to compiler and Intermedia Language (IL)
  • 47. PowerMock ✤ 介紹Concept & open source example
  • 49. FAQ ✤ Difference between Stub and Mock
 http://williamherry.com/blog/2013/05/13/understand-stub-and-mock/ ✤ Unit Test vs Integration Test
 https://www.guru99.com/unit-test-vs-integration-test.html ✤ Unit Test pattern
 http://xunitpatterns.com/index.html ✤ Unit Test Principle
 https://github.com/ghsukumar/SFDC_Best_Practices/wiki/F.I.R.S.T- Principles-of-Unit-Testing

  • 50. Author Recommended ✤ Unit Test Pattern:
 XUnit Test Pattern: Refactoring Test ✤ Legacy Code:
 Working Effectively with Legacy Code ✤ CI/CD:
 Continuous Integration: Improving Software Quality and Reducing Risk
  • 52. Conclusion ✤ Unit Test vs Integration Test ✤ Test Double ✤ Key Point of Unit Test ✤ Three Success Key Factor of Unit Test ✤ Isolation framework ✤ FAQ
  • 54. How many kinds of testing term? ✤ https://www.utest.com/articles/ 8-best-software-testing-books-qa- engineer--tester-must-read ✤ Wiki : Software testing
 https://en.wikipedia.org/wiki/ Software_testing ✤ Types of Software Testing
 http:// www.softwaretestinghelp.com/ types-of-software-testing/
  • 56. Reference ✤ Notes of The Art of Unit Testing
 https://blog.miniasp.com/post/2010/02/21/The-Art-of- Unit-Testing-with-Roy-Osherove-Notes.aspx ✤ https://www.guru99.com/unit-test-vs-integration-test.html ✤ Good slides from docker
 https://www.slideshare.net/rheinwein/stop-being-lazy- and-test-your-software? qid=2256a3e5-0099-40be-9a8e-6114ceec068b&v=&b=&from_s earch=5
  • 57. Reference ✤ 5 test double type
 http://oomusou.io/jasmine/jasmine-test-double/ ✤ XUnit Test Patterns
 http://xunitpatterns.com/index.html ✤ Testing tutorial
 https://www.tutorialspoint.com/software_testing