SlideShare a Scribd company logo
1 of 26
Download to read offline
11
Unit Test
Danna Wang
2
Problems when you add a logic or
finish a function
3
PROBLEMS
Why
Unit Test
● Satisfy with requirement,verification function
implementation
● Protecting business value
● Confidence in making change
● Protect existing functions from being broken
● Communication to next developer
● Quickly know if the software is broken
4
“I need someone who
has a different perspective to show me what I’ve missed.”
5
Still need QA(Quality Assurance)
6
Agile Testing
手动测试
黑盒测试
集成测试
冒烟测试
…...
Types of testing
7
TYPES
8
● Integration test
● Automated test
● Regression test
● Manual test
● Smoke test
● UI test
● E2E test
● Contract test
● UAT(User Acceptance Test)
9
Test
pyramid
©ThoughtWorks 2019 Commercial in Confidence
测试金字塔
一个健康、快速、可维护的测试组合
独立
What’s a good unit test
10
“A unit test is an automated piece
of code that invokes a unit of work
in the system and then checks a
single assumption about the
behavior of that unit of work.
- Roy Osherove (Art of unit testing)”
Unit Test 是指对软件中的最小可测试单元进行检查和验证。
11
What’s a Unit
12
DIRECT AGENT/
FLEET ENGAGEMENT
SPEED OF
DELIVERY
©ThoughtWorks 2019 Commercial in Confidence
● 一个 Function?
● 一个 Class?
● 一个最小的业务单元?
“ 一千个人心中有一千种单元测试 ”
13
DIRECT AGENT/
FLEET ENGAGEMENT
SPEED OF
DELIVERY
©ThoughtWorks 2019 Commercial in Confidence
Principle
14
SUPPLY
AUTOMATION
DIRECT AGENT/
FLEET ENGAGEMENT
SPEED OF
DELIVERY
What’s a good Unit test
15
SUPPLY
AUTOMATION
DIRECT AGENT/
FLEET ENGAGEMENT
SPEED OF
DELIVERY
©ThoughtWorks 2019 Commercial in Confidence
● 避免进行真实的数据库操作、文件系统操作
● 独立地测试代码库的每一小块
● 正确重演业务,Do & Not do
● 包括正常 Case 和边缘 Case
● 测 “1+1=2” 这种没营养的单元吗? 100%?
How to write a good Unit test
16
SUPPLY
AUTOMATION
SPEED OF
DELIVERY
● Arrange
● Act
● Assert
● Given
● When
● Then
Basic test skeleton
17©ThoughtWorks 2019 Commercial in Confidence
Unit test example
18
DIRECT AGENT/
FLEET ENGAGEMENT
SPEED OF
DELIVERY
©ThoughtWorks 2019 Commercial in Confidence
Tools for testing
19©ThoughtWorks 2019 Commercial in Confidence
Tools for Testing
20
● Jasmine
● Mocha
● JUnit
● Selenium
● REST-assured
Examples
21
Example No.1
22
Example No.2
User need a tool, so they can calculate the max number in any array.
Scenario User start to type a array
Given a array with 5 different number
When user use this tool
Then user should get the max number
Given a empty array
When user use this tool
Then user should be informed they input a empty array
23
Practice time
24
请补全 Average 函数的测试
25
Happy testing
Thank you
26©ThoughtWorks 2019 Commercial in Confidence

More Related Content

What's hot

Test Automation Principles
Test Automation PrinciplesTest Automation Principles
Test Automation Principles
NetSuite
 
Agile tour ncr test360_degree - agile testing on steroids
Agile tour ncr test360_degree - agile testing on steroidsAgile tour ncr test360_degree - agile testing on steroids
Agile tour ncr test360_degree - agile testing on steroids
Vipul Gupta
 

What's hot (20)

Large-Scale Agile Test Automation Strategies in Practice
Large-Scale Agile Test Automation Strategies in PracticeLarge-Scale Agile Test Automation Strategies in Practice
Large-Scale Agile Test Automation Strategies in Practice
 
7 Deadly Sins of Agile Software Test Automation
7 Deadly Sins of Agile Software Test Automation7 Deadly Sins of Agile Software Test Automation
7 Deadly Sins of Agile Software Test Automation
 
Use Automation to Assist—Not Replace—Manual Testing
Use Automation to Assist—Not Replace—Manual TestingUse Automation to Assist—Not Replace—Manual Testing
Use Automation to Assist—Not Replace—Manual Testing
 
Test automation - What? Why? How?
Test automation - What? Why? How?Test automation - What? Why? How?
Test automation - What? Why? How?
 
What is Agile Testing?
What is Agile Testing?What is Agile Testing?
What is Agile Testing?
 
Optimizing Your Agile Testing Processes
Optimizing Your Agile Testing ProcessesOptimizing Your Agile Testing Processes
Optimizing Your Agile Testing Processes
 
James Whittaker - Pursuing Quality-You Won't Get There - EuroSTAR 2011
James Whittaker - Pursuing Quality-You Won't Get There - EuroSTAR 2011James Whittaker - Pursuing Quality-You Won't Get There - EuroSTAR 2011
James Whittaker - Pursuing Quality-You Won't Get There - EuroSTAR 2011
 
Agile test tools
Agile test toolsAgile test tools
Agile test tools
 
Achieve Intelligent Test Execution: Strategies for Streamlining Regression Te...
Achieve Intelligent Test Execution: Strategies for Streamlining Regression Te...Achieve Intelligent Test Execution: Strategies for Streamlining Regression Te...
Achieve Intelligent Test Execution: Strategies for Streamlining Regression Te...
 
Test Automation Pyramid
Test Automation PyramidTest Automation Pyramid
Test Automation Pyramid
 
Using AI-Powered Visual Tests to empower your tests
Using AI-Powered Visual Tests to empower your testsUsing AI-Powered Visual Tests to empower your tests
Using AI-Powered Visual Tests to empower your tests
 
Test Automation Principles
Test Automation PrinciplesTest Automation Principles
Test Automation Principles
 
Roman iovlev battle - JDI vs Selenide - Selenium Camp
Roman iovlev battle - JDI vs Selenide - Selenium CampRoman iovlev battle - JDI vs Selenide - Selenium Camp
Roman iovlev battle - JDI vs Selenide - Selenium Camp
 
Agile tour ncr test360_degree - agile testing on steroids
Agile tour ncr test360_degree - agile testing on steroidsAgile tour ncr test360_degree - agile testing on steroids
Agile tour ncr test360_degree - agile testing on steroids
 
Thomas Kauders - Agile Test Design And Automation of a Life-Critical Medical ...
Thomas Kauders - Agile Test Design And Automation of a Life-Critical Medical ...Thomas Kauders - Agile Test Design And Automation of a Life-Critical Medical ...
Thomas Kauders - Agile Test Design And Automation of a Life-Critical Medical ...
 
ATDD with cucumber java talk at DevOpsQANJ meetup aug 11 2016
ATDD with cucumber java talk at DevOpsQANJ meetup aug 11 2016ATDD with cucumber java talk at DevOpsQANJ meetup aug 11 2016
ATDD with cucumber java talk at DevOpsQANJ meetup aug 11 2016
 
Agile in planday
Agile in plandayAgile in planday
Agile in planday
 
Introduction to TDD and BDD
Introduction to TDD and BDDIntroduction to TDD and BDD
Introduction to TDD and BDD
 
Test pyramid
Test pyramidTest pyramid
Test pyramid
 
Test Automation Strategies For Agile
Test Automation Strategies For AgileTest Automation Strategies For Agile
Test Automation Strategies For Agile
 

Similar to Unit Test (单元测试)

A Complete Guide to Functional Testing
A Complete Guide to Functional TestingA Complete Guide to Functional Testing
A Complete Guide to Functional Testing
Abhay Kumar
 
Testing & continuous delivery
Testing & continuous deliveryTesting & continuous delivery
Testing & continuous delivery
Nelson Melina
 

Similar to Unit Test (单元测试) (20)

Testing strategies and best practices using MUnit
Testing strategies and best practices using MUnitTesting strategies and best practices using MUnit
Testing strategies and best practices using MUnit
 
PMI-ACP Lesson 06 Quality
PMI-ACP Lesson 06 QualityPMI-ACP Lesson 06 Quality
PMI-ACP Lesson 06 Quality
 
High Performance Software Engineering Teams
High Performance Software Engineering TeamsHigh Performance Software Engineering Teams
High Performance Software Engineering Teams
 
Unit testing
Unit testingUnit testing
Unit testing
 
Are Your Continuous Tests Too Fragile for Agile?
Are Your Continuous Tests Too Fragile for Agile?Are Your Continuous Tests Too Fragile for Agile?
Are Your Continuous Tests Too Fragile for Agile?
 
Engineering Trust in Your Automated Tests
Engineering Trust in Your Automated TestsEngineering Trust in Your Automated Tests
Engineering Trust in Your Automated Tests
 
RDz for DevOps Webcast Series: Implementing Continuous Integration with RDz
RDz for DevOps Webcast Series: Implementing Continuous Integration with RDzRDz for DevOps Webcast Series: Implementing Continuous Integration with RDz
RDz for DevOps Webcast Series: Implementing Continuous Integration with RDz
 
Just Java2007 - Daniel Wildt - Tools For Java Test Automation
Just Java2007 - Daniel Wildt - Tools For Java Test AutomationJust Java2007 - Daniel Wildt - Tools For Java Test Automation
Just Java2007 - Daniel Wildt - Tools For Java Test Automation
 
Test your code
Test your codeTest your code
Test your code
 
Verification and validation
Verification and validationVerification and validation
Verification and validation
 
Agile Development of High Performance Applications
Agile Development of High Performance ApplicationsAgile Development of High Performance Applications
Agile Development of High Performance Applications
 
A Complete Guide to Functional Testing
A Complete Guide to Functional TestingA Complete Guide to Functional Testing
A Complete Guide to Functional Testing
 
Agile Testing - What is it?
Agile Testing - What is it?Agile Testing - What is it?
Agile Testing - What is it?
 
Agile Testing
Agile Testing  Agile Testing
Agile Testing
 
Wso2con test-automation
Wso2con test-automationWso2con test-automation
Wso2con test-automation
 
Android testing part i
Android testing part iAndroid testing part i
Android testing part i
 
Optimizely NYC Developer Meetup - Experimentation at Blue Apron
Optimizely NYC Developer Meetup - Experimentation at Blue ApronOptimizely NYC Developer Meetup - Experimentation at Blue Apron
Optimizely NYC Developer Meetup - Experimentation at Blue Apron
 
Testing & continuous delivery
Testing & continuous deliveryTesting & continuous delivery
Testing & continuous delivery
 
Testing experience - Vision team, Mar 2016
Testing experience - Vision team, Mar 2016Testing experience - Vision team, Mar 2016
Testing experience - Vision team, Mar 2016
 
A Complete Guide to Functional Testing
A Complete Guide to Functional TestingA Complete Guide to Functional Testing
A Complete Guide to Functional Testing
 

More from Amber49

More from Amber49 (8)

React
ReactReact
React
 
Web Accessibility ( Web 无障碍访问 )
Web Accessibility  ( Web 无障碍访问 )Web Accessibility  ( Web 无障碍访问 )
Web Accessibility ( Web 无障碍访问 )
 
Flex layout ( Flex 布局 )
Flex layout ( Flex 布局 )Flex layout ( Flex 布局 )
Flex layout ( Flex 布局 )
 
HTTP Caching ( HTTP 缓存策略 )
HTTP Caching ( HTTP 缓存策略 )HTTP Caching ( HTTP 缓存策略 )
HTTP Caching ( HTTP 缓存策略 )
 
Chinese characters (中国汉字 )
Chinese characters (中国汉字 )Chinese characters (中国汉字 )
Chinese characters (中国汉字 )
 
12 Constellations (星座)
12 Constellations (星座)12 Constellations (星座)
12 Constellations (星座)
 
PWA
PWAPWA
PWA
 
Daily English Tips
Daily English TipsDaily English Tips
Daily English Tips
 

Recently uploaded

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 

Recently uploaded (20)

Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 

Unit Test (单元测试)