2016-02-20 aftership - how we do testing
Post on 22-Jan-2018
272 Views
Preview:
TRANSCRIPT
Goal and Agenda
● Overview of the AfterShip development cycle
● Concept of Testing
● Writing Good Tests
Tools That Helped Us
● Github (Code Repository)
● Travis CI (Continuous Integration Tool)
● Codecov (Test Coverage Report)
● Runscope (Automated Request Runner)
Tools That Helped Us
● Github (Code Repository)
● Travis CI (Continuous Integration Tool)
● Codecov (Test Coverage Report)
● Runscope (Automated Request Runner)Automated
Testing
OutcomesAction
● Identified problems before they arise
● Enforced best practices
● Reduced human error
Plan
● Decrease bugs
● Do more tests
● Automate some tasks
Why is testing still limited?
● Time consuming/Laziness
● Lack of foresight
● Overconfidence
● Don’t know how to write tests
Scope of Each Type of Test
● Functional/End-to-End ○ Biggest
○ Every components
● Integration○ Smaller
○ 2 or more components
● Unit○ Smallest
○ Single component/unit/function
Example
Check if the dumpling is edible or not
Source: doctoringdancinganddelectables.wordpress.com
What you would normally do
1. Observe the appearance
2. Smell the dumpling
3. Take a peek inside
4. Feel the texture
5. Taste it
6. Ask the server if the dumpling is cooked
What if you can just do this?
1. Separate the components of a dumpling
2. Know the process of cooking a dumpling
3. Inspect them individually
4. Cook a batch of dumpling
5. Try one to see if it meets expectation
6. Serve
Separate into components
1. Peel
2. Chicken/Pork
3. Shrimp
4. Spring Onion
Source: doctoringdancinganddelectables.wordpress.com
The process of cooking dumpling
1. Prepare the steamer
2. Put water in the steamer
3. Boil the water
4. Steam
Inspect Them Individually
1. Peel a. is it white?b. is it firm?c. no molds?
2. Chicken/Porka. is it fresh?b. no molds?
3. Shrimpa. no molds?b. pungent smell?
4. Spring Oniona. green?
1. Put in the steamera. is the steamer ok?
2. Put water in the steamera. is it using drinking water?
3. Boil the watera. is the water hot enough?
4. Steama. is there steam?
Put the Dumpling in the steamer
1. Is the steam getting to the dumpling?
2. Will the dumpling stay in place?
From the batch of dumpling
● Pick one and taste.
○ If it is undercooked?
○ If it is spoiled?
○ It there are holes?
● Testing 2 or more components or units together
What is Integration Testing?
DB Access Layer
DB
only test the two components
Model
Controllers
What is Unit Testing?
● Testing a single unit to make sure it works● It is fast and more reliable● Isolates a unit
DB Access Layer
DB
ModelsYour System
External System
Controllers
Test Pyramid
● Fail earlier
● Fail faster (test speed)
● Easy to identifier the bug
● 70/20/10 split
General Rules on Unit Testing
● Trust nothing
● Only test what you care about
● Avoid dependencies as much as possible
● Make sure it runs
Node.js Specific Tools
● Grunt (Automation)● Mocha (Testing Framework)● Istanbul (Coverage Report) / Sparta● Mocking Libraries
○ Sinon
○ Proxyquire
○ Rewire
real server << fake server | mocking
Code Example
● https://github.com/AfterShip/demo-unit-tests
The Future?
● More Unit Test, Less E2E test
○ Follow the 70:20:10 model
● Automate more tests including some end to end tests and
integration tests
Continuous Integration
● Version control
● Automated testing for every commit
● Commit to baseline - reason to avoid long / super big conflict, avoid
behind a lot
● Staging environment
● Easy to access release archives - tag
● Easy to view test results - Travis CI result
● Automate deployment
AfterShip Continuous Integration
● Version control
● Automated testing for every commit
● Commit to baseline - reason to avoid long / super big conflict, avoid
behind a lot
● Staging environment
● Easy to access release archives - tag
● Easy to view test results - Travis CI result
● Automate deployment
top related