34
Full testzdec Andrii Shumada Lazy Sr. Software Developer at eagleeye eagleeye_s [email protected]

Повний тестздець SPA + REST

Embed Size (px)

Citation preview

Page 1: Повний тестздець SPA + REST

Full testzdec

Andrii Shumada

Lazy Sr. Software Developer at

[email protected]

Page 2: Повний тестздець SPA + REST

Why we should write tests

Page 3: Повний тестздець SPA + REST

Why this project cannot start on my computer?

Victor VyshnevskyTrainee at JsSolutions

- Typo/error in your code- Wrong version of global

module (mongo, node)- Not compatible OS/browser- Floating version of package(

2.x, ~3.5.2, >=1.5.0)- Floating version of

subpackage- Npm package was deleted

from npm- 3rd party service changed

their API or died

Page 4: Повний тестздець SPA + REST

How the common test looks like?

Page 5: Повний тестздець SPA + REST

sync setup

Page 6: Повний тестздець SPA + REST

async setup

Page 7: Повний тестздець SPA + REST

Actual test

Page 8: Повний тестздець SPA + REST

Unit tests run

Unit tests

require function call

Compare actual result with expected

Page 9: Повний тестздець SPA + REST

gocardlessFactory.js

gocardlessFactory.spec.js

Page 10: Повний тестздець SPA + REST

Integration tests

JSON REST API Integration tests

<- send JSON-> get JSON check json

Page 11: Повний тестздець SPA + REST

2 unit tests, 0 integration

Page 12: Повний тестздець SPA + REST
Page 13: Повний тестздець SPA + REST
Page 14: Повний тестздець SPA + REST

End-to-end tests (client tests)

JSON REST API

Client test

Open pageInteracts with pageChecks DOM

<- send JSON-> get JSON

Client (browser) ⇔ webdriver protocol

Page 15: Повний тестздець SPA + REST

http://webdriver.io/

Page 16: Повний тестздець SPA + REST

How do you feel when you see this

Page 17: Повний тестздець SPA + REST

What do you use to lint your code?

Page 18: Повний тестздець SPA + REST

How do you run this lint?

Package.json

{ “scripts”: { “test”: “mocha test && jshint lib/** && csslint client/css/**” }}

Page 19: Повний тестздець SPA + REST

Linting could also be a test!

https://www.npmjs.com/package/mocha-jshint

https://www.npmjs.com/package/mocha-csslint

https://www.npmjs.com/package/mocha-eslint

https://www.npmjs.com/package/mocha-jscs

eslint.spec.js

Page 20: Повний тестздець SPA + REST

Who is guilty?

Page 21: Повний тестздець SPA + REST
Page 22: Повний тестздець SPA + REST
Page 23: Повний тестздець SPA + REST
Page 24: Повний тестздець SPA + REST
Page 25: Повний тестздець SPA + REST

- Tests should run before merging branch to master

- Tests should work on Continous Integration server

(Travis, Jenkins, TeamCity, CircleCI)

Page 26: Повний тестздець SPA + REST

Why this project cannot start on my computer?

- Typo/error in your code- Wrong version of global

module (mongo, node)- Not compatible OS/browser- Floating version of package(

2.x, ~3.5.2, >=1.5.0)- Floating version of

subpackage- Npm package was deleted

from npm- 3rd party service changed

their API/died)

Page 27: Повний тестздець SPA + REST

How to check wrong version of node?

+ nodeversioncheck

$ node app.jsRunning correct node V5.8.0. (according to package.json we need V5.8.0)

or$ node app.jsRunning WRONG node V5.8.0. (according to package.json we need V7.8.0)

Page 28: Повний тестздець SPA + REST

.travis.yml

Node 0.10Mongo 2.6

Node 0.12Mongo 2.6

Node iojsMongo 2.6

Node 0.10Mongo 2.8

Node 0.12Mongo 2.8

Node iojsMongo 2.8

Node 0.10Mongo 3.0

Node 0.12Mongo 3.0

Node iojsMongo 3.0

Page 29: Повний тестздець SPA + REST

Why this project cannot start on my computer?

- Typo/error in your code- Wrong version of global

module (mongo, node)- Not compatible OS/browser- Floating version of package(

2.x, ~3.5.2, >=1.5.0)- Floating version of

subpackage- Npm package was deleted

from npm- 3rd party service changed

their API/died)

Page 30: Повний тестздець SPA + REST

Nightly test!Schedule all your tests on master to run during night!

rm -rf node modulesnpm inpm test

Page 31: Повний тестздець SPA + REST

Your team will use tests when they will be:

- Stable (minimize radom things)- Valuable (check only what make sense) - They should work on your machine, machines of your colleges and

on CI server (setup contionius integration)- Fast enough to use it (slow tests should go to nightly-test)- Easy to write ( declaritive style of setup )- Easy to maintain

Page 32: Повний тестздець SPA + REST

Examples of bad tests

Page 33: Повний тестздець SPA + REST

Example of bad test (2)