2016-02-20 aftership - how we do testing

37
How We Do Testing Rick [email protected]

Upload: aftership

Post on 22-Jan-2018

272 views

Category:

Technology


5 download

TRANSCRIPT

How We Do TestingRick

[email protected]

Goal and Agenda

● Overview of the AfterShip development cycle

● Concept of Testing

● Writing Good Tests

In the Beginning

● Undetected bugs

● Limited test coverage

● Tedious and repetitive tests

How can we improve?

● Decrease bugs

● Do more tests

● Automate some tasks

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

Then What Happened?

OutcomesAction

● Identified problems before they arise

● Enforced best practices

● Reduced human error

Plan

● Decrease bugs

● Do more tests

● Automate some tasks

Limitations

● Code may become slower

● Increases development time

● Cannot guarantee perfect code

Was The Move Justifiable?

Why is testing still limited?

● Time consuming/Laziness

● Lack of foresight

● Overconfidence

● Don’t know how to write tests

Concept of Testing

Types of Testing

● Functional/End-to-End

● Integration

● Unit

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

How many dumplings would you have wasted

doing the process above?

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?

What method do you think is better?

What is End-to-End test?

● Create the account

Web Server DB

create account

● 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

Questions?

Thank You

Appendix

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