js lab`16. Сергей Селецкий: "Ретроспектива тестирования...

67
РЕТРОСПЕКТИВА ТЕСТОВЫХ ИСТРУМЕНТОВ ДЛЯ JAVASCRIPT СЕРГЕЙ СЕЛЕЦКИЙ @SSELETSKYY

Upload: geekslab-odessa

Post on 14-Apr-2017

213 views

Category:

Software


5 download

TRANSCRIPT

Page 1: JS Lab`16. Сергей Селецкий: "Ретроспектива тестирования JavaScript"

РЕТРОСПЕКТИВА ТЕСТОВЫХ ИСТРУМЕНТОВ

ДЛЯ JAVASCRIPT СЕРГЕЙ СЕЛЕЦКИЙ

@SSELETSKYY

Page 2: JS Lab`16. Сергей Селецкий: "Ретроспектива тестирования JavaScript"

ПРОВЕРКА МИКРОФОНА

Page 3: JS Lab`16. Сергей Селецкий: "Ретроспектива тестирования JavaScript"

О ЧЕМ МЫ ПОГОВОРИМ• КАКИЕ ИНСТРУМЕНТЫ БЫЛИ ЗА ПОСЛЕДНИЕ 12 ЛЕТ

• СРАВНЕНИЕ СТИЛЕЙ ОПИСАНИЯ ТЕСТОВ

• ВЫБОР МЕЖДУ ПРОСТОЙ БИБЛИОТЕКОЙ И МУЛЬТИВАРКОЙ или КРАТКИЕ ОБЗОР

• КАКИЕ ТЕНДЕНЦИИ СВЕТЛОГО БУДУЩЕГО? (вопросы к аудитории)

Page 4: JS Lab`16. Сергей Селецкий: "Ретроспектива тестирования JavaScript"

А КАКОГО ЭТО НУЖНО?

Page 5: JS Lab`16. Сергей Селецкий: "Ретроспектива тестирования JavaScript"

Я ВИТРАТИВ ЦІЛИЙ ТИЖДЕНЬ ЩОБ НАПИСАТИ ЦЕЙ ТЕСТ ДЛЯ НАШОГО ПРОДУКТУ

Page 6: JS Lab`16. Сергей Селецкий: "Ретроспектива тестирования JavaScript"

А Я НАПИСАВ ТЕСТ ЩОБ ПЕРЕВІРИТИ ТЕСТ ДМИТРА

Page 7: JS Lab`16. Сергей Селецкий: "Ретроспектива тестирования JavaScript"

ТВІЙ ТЕСТ БУВ МАЙЖЕ ДОСКОНАЛИМ

ОТОЖ ПРОДОВЖУЙ ГАРНО ПРАЦЮВАТИ, ДМИТРИКУ

Page 8: JS Lab`16. Сергей Селецкий: "Ретроспектива тестирования JavaScript"

ИНСТРУМЕНТЫ

Page 9: JS Lab`16. Сергей Селецкий: "Ретроспектива тестирования JavaScript"

• 2004 - ?

Page 10: JS Lab`16. Сергей Селецкий: "Ретроспектива тестирования JavaScript"

• 2004 - SELENIUM -> WEB DRIVER

Page 11: JS Lab`16. Сергей Селецкий: "Ретроспектива тестирования JavaScript"

• 2004 - SELENIUM -> WEB DRIVER • 2007 - JSSpec (BDD framework)

Page 12: JS Lab`16. Сергей Селецкий: "Ретроспектива тестирования JavaScript"

• 2004 - SELENIUM -> WEB DRIVER • 2007 - JSSpec • 2008 - Screw.Unit

Page 13: JS Lab`16. Сергей Селецкий: "Ретроспектива тестирования JavaScript"

• 2004 - SELENIUM -> WEB DRIVER • 2007 - JSSpec • 2008 - Screw.Unit, QUnit

Page 14: JS Lab`16. Сергей Селецкий: "Ретроспектива тестирования JavaScript"

• 2004 - SELENIUM -> WEB DRIVER • 2007 - JSSpec • 2008 - Screw.Unit, QUnit,

FireUnit, Blue Ridge

Page 15: JS Lab`16. Сергей Селецкий: "Ретроспектива тестирования JavaScript"

• 2004 - SELENIUM -> WEB DRIVER • 2007 - JSSpec • 2008 - Screw.Unit, QUnit,

FireUnit, Blue Ridge, Sugar Test, jShoulda

Page 16: JS Lab`16. Сергей Селецкий: "Ретроспектива тестирования JavaScript"

• 2004 - SELENIUM -> WEB DRIVER • 2007 - JSSpec • 2008 - Screw.Unit, QUnit,

FireUnit, Blue Ridge, Sugar Test, jShoulda JSpec, Jasmine

Page 17: JS Lab`16. Сергей Селецкий: "Ретроспектива тестирования JavaScript"

• 2009 - TestSwarm, Inspec, YUI Test

Page 18: JS Lab`16. Сергей Селецкий: "Ретроспектива тестирования JavaScript"

• 2009 - TestSwarm, Inspec, YUI Test • 2010 - Sinon.js, JSLint, JSLitmus, JSHint

Page 19: JS Lab`16. Сергей Селецкий: "Ретроспектива тестирования JavaScript"

• 2009 - TestSwarm, Inspec, YUI Test • 2010 - Sinon.js, JSLint, JSLitmus, JSHint • 2011 - Mocha.js, Karma, Buster

Page 20: JS Lab`16. Сергей Селецкий: "Ретроспектива тестирования JavaScript"

• 2009 - TestSwarm, Inspec, YUI Test • 2010 - Sinon.js, JSLint, JSLitmus, JSHint • 2011 - Mocha.js, Karma, Buster • 2012 - Intern, Nightwatch.js

Page 21: JS Lab`16. Сергей Селецкий: "Ретроспектива тестирования JavaScript"

• 2009 - TestSwarm, Inspec, YUI Test • 2010 - Sinon.js, JSLint, JSLitmus, JSHint • 2011 - Mocha.js, Karma, Buster • 2012 - Intern, Nightwatch.js • 2013 - Protractor, ReactTestUtils

Page 22: JS Lab`16. Сергей Селецкий: "Ретроспектива тестирования JavaScript"

• 2009 - TestSwarm, Inspec, YUI Test • 2010 - Sinon.js, JSLint, JSLitmus, JSHint • 2011 - Mocha.js, Karma, Buster • 2012 - Intern, Nightwatch.js • 2013 - Protractor, ReactTestUtils • 2014 - Jest (React), Machiatto, Ava

Page 23: JS Lab`16. Сергей Селецкий: "Ретроспектива тестирования JavaScript"

• 2009 - TestSwarm, Inspec, YUI Test • 2010 - Sinon.js, JSLint, JSLitmus, JSHint • 2011 - Mocha.js, Karma, Buster • 2012 - Intern, Nightwatch.js • 2013 - Protractor, ReactTestUtils • 2014 - Jest (React), Machiatto, Ava • 2015 - Yolpo

Page 24: JS Lab`16. Сергей Селецкий: "Ретроспектива тестирования JavaScript"
Page 25: JS Lab`16. Сергей Селецкий: "Ретроспектива тестирования JavaScript"
Page 26: JS Lab`16. Сергей Селецкий: "Ретроспектива тестирования JavaScript"

СТИЛИ ТЕСТОВ

Page 27: JS Lab`16. Сергей Селецкий: "Ретроспектива тестирования JavaScript"

ASSERT SHOULD EXPECT

🙀 😺 😻

СТИЛИ ПРОВЕРОК

Page 28: JS Lab`16. Сергей Селецкий: "Ретроспектива тестирования JavaScript"

DESCRIBE { IT { EXPECT() } }

TEST { ASSERT() }

CONTEXT { SHOULD() }

🙀

СТИЛИ БЛОКОВ

SPEC.WHEN() .AND() .SHOULD()

TEST('foo', t => { t.pass() })new Y.Test.Case({testName: function() {…}})

😻

😺

Page 29: JS Lab`16. Сергей Селецкий: "Ретроспектива тестирования JavaScript"

{блоки}

Page 30: JS Lab`16. Сергей Селецкий: "Ретроспектива тестирования JavaScript"

{блоки}или .цепочки.

Page 31: JS Lab`16. Сергей Селецкий: "Ретроспектива тестирования JavaScript"

КРАТКИЙ ОБЗОР

Page 32: JS Lab`16. Сергей Селецкий: "Ретроспектива тестирования JavaScript"

Intern Software testing for humans

Features

• Write tests in JavaScript using any style you like (TDD, BDD, whatever!).

• Run tests straight from your browser, right in Node.js, or against many browsers & platforms at the same time with the Intern test runner.

• Get full code coverage reporting so you know what’s left to test.

• Seamlessly run tests on Sauce Labs, BrowserStack, TestingBot, or your own Selenium Grid.

• Ready for continuous integration? Intern fully integrates with Travis CI, Jenkins, and TeamCity out of the box.

https://theintern.github.io/

Page 33: JS Lab`16. Сергей Селецкий: "Ретроспектива тестирования JavaScript"

Intern What can Intern do that others can’t?

Page 34: JS Lab`16. Сергей Селецкий: "Ретроспектива тестирования JavaScript"

Intern What can Intern do that others can’t?

😺😺

Page 35: JS Lab`16. Сергей Селецкий: "Ретроспектива тестирования JavaScript"

Jasmine

Jasmine is a Behavior Driven Development testing framework for JavaScript. It does not rely on browsers, DOM, or any JavaScript framework. Thus it's suited for websites, Node.js projects, or anywhere that JavaScript can run.Features • Simple setup for node through jasmine-node • Headless running out of the box • Nice fluent syntax for assertions built-in, and does play pretty well with other assertion libraries

• Supported by many CI servers (TeamCity, Codeship, etc.) • Descriptive syntax for BDD paradigm

Nov 23, 2008 – Mar, 2016

https://github.com/jasmine/jasmine

Page 36: JS Lab`16. Сергей Селецкий: "Ретроспектива тестирования JavaScript"

Jasmine Nov 23, 2008 – Mar, 2016

describe("A suite", function() { it("contains spec with an expectation", function() { expect(true).toBe(true); }); });

Page 37: JS Lab`16. Сергей Селецкий: "Ретроспектива тестирования JavaScript"

Mocha.js

Mocha is a simple, flexible, fun JavaScript test framework for node.js and the browser. Features • Simple setup • Asynchronous testing is a breeze • Headless running out of the box

• Allows use of any assertion library that will throw exceptions on failure, such as Chai • Supported by some CI servers and plugins for others (jenkins has a maven plugin) • Has aliases for functions to be more BDD-oriented or TDD-oriented • Highly extensible

Aug 28, 2011 – Mar, 2016

https://github.com/mochajs/mocha

Page 38: JS Lab`16. Сергей Селецкий: "Ретроспектива тестирования JavaScript"

Mocha.js

Assertion Libraries • should.js - BDD style shown throughout these docs • chai - expect(), assert() and should style assertions • expect.js - expect() style assertions • expectations - Jasmine-style expect() • unit.js - simple, fluent assertions • unexpected - extensible BDD assertion toolkit

Aug 28, 2011 – Mar, 2016

Page 39: JS Lab`16. Сергей Селецкий: "Ретроспектива тестирования JavaScript"

machiattobehavior driven test framework

Features • BDD friendly syntax • Context re-use between tests and files • Better structure for same context tests • Sync and async code testing • Browser and node.js

May 18, 2014 – Nov, 2014

https://github.com/alexbeletsky/machiatto

Page 40: JS Lab`16. Сергей Селецкий: "Ретроспектива тестирования JavaScript"

machiatto

second argument is missing a context re-use

Context re-use between tests and files

Page 41: JS Lab`16. Сергей Селецкий: "Ретроспектива тестирования JavaScript"

AvaFuturistic test runner

Even though JavaScript is single-threaded, IO in Node.js can happen in parallel due to its async nature. AVA takes advantage of this and runs your tests concurrently, which is especially beneficial for IO heavy tests. In addition, test files are run in parallel as separate processes, giving you even better performance and an isolated environment for each test file.

Switching from Mocha to AVA in Pageres brought the test time down from 31 sec to 11 sec.

Having tests run concurrently forces you to write atomic tests, meaning tests don't depend on global state or the state of other tests, which is a great thing!

Nov 16, 2014 – Mar, 2016

https://github.com/sindresorhus/ava

Page 42: JS Lab`16. Сергей Селецкий: "Ретроспектива тестирования JavaScript"

AvaFuturistic test runner

Nov 16, 2014 – Mar, 2016

test(t => { t.plan(1);

return Promise.resolve(3).then(n => { t.is(n, 3); }); });

test.cb(t => { t.plan(1);

someAsyncFunction(() => { t.pass(); t.end(); }); });

Page 43: JS Lab`16. Сергей Селецкий: "Ретроспектива тестирования JavaScript"

Nightwatch.jsUI automated testing framework

Nightwatch.js is an easy to use Node.js based End-to-End (E2E) testing solution for browser based apps and websites. It uses the powerful Selenium WebDriver API to perform commands and assertions on DOM elements.

Main Features • Clean syntax • Selenium server • CSS & Xpath support • Easy to extend • Built-in test runner • Cloud services support • Continuous integration support

Mar 11, 2012 – Feb, 2016

https://github.com/nightwatchjs/nightwatchhttp://nightwatchjs.org/

Page 44: JS Lab`16. Сергей Селецкий: "Ретроспектива тестирования JavaScript"

Nightwatch.jsUI automated testing framework

Mar 11, 2012 – Feb, 2016

module.exports = { 'Demo test Google' : function (browser) { browser .url('http://www.google.com') .waitForElementVisible('body', 1000) .setValue('input[type=text]', 'nightwatch') .waitForElementVisible('button[name=btnG]', 1000) .click('button[name=btnG]') .pause(1000) .assert.containsText('#main', 'Night Watch') .end(); } };

Page 45: JS Lab`16. Сергей Селецкий: "Ретроспектива тестирования JavaScript"

YolpoA tool to see the execution of plain and simple javascript code

May 3, 2015 – Jul, 2015

• Tests do not rely upon any other library except the one they are testing • Tests are 100% javascript. • Tests are running on the browser • Use Gist GitHub to store code; then get yolpo to run it.

https://github.com/lorenzoongithub/yolpohttp://www.yolpo.com/

Page 46: JS Lab`16. Сергей Селецкий: "Ретроспектива тестирования JavaScript"

http://www.yolpo.com/player/v.html?gist=d2d19a00747991285307&autoplay=2

Page 47: JS Lab`16. Сергей Селецкий: "Ретроспектива тестирования JavaScript"

JSLitmusJavaScript benchmark testing made easy

Aug 22, 2010 - Aug 27, 2010

JSLitmus is a lightweight tool for creating ad-hoc JavaScript benchmark tests. Features • Single-file install (JSLitmus.js) • Works on Firefox, Opera, Safari, IE, Google Chrome, and iPhone browsers • Works in node.js • Adaptive test cycles - tests take ~1-2 seconds, regardless of the operation • Google Chart + TinyUrl integration • Open Source MIT-style license (see source)

JSLitmus determines the performance of your code by running it repeatedly until a sufficient amount of time has passed to obtain a valid result. This requires an iteration loop, of course. But for fast operations - operations that can be run more than ~100K/second or more - the overhead of the iteration loop can overshadow the performance of your test code. JSLitmus has two features that address this issue.

http://www.broofa.com/Tools/JSLitmus/ https://github.com/broofa/jslitmus

Page 48: JS Lab`16. Сергей Селецкий: "Ретроспектива тестирования JavaScript"

JSLitmus <script src="jslitmus.js"></script> <script> // Create a test to see how fast Array.join() is on 10K elements var a = new Array(10000); jslitmus.test('Join 10K elements', function() { a.join(' '); });

// Log the test results jslitmus.on('complete', function(test) { console.log(test); });

// Run it! jslitmus.runAll(); </script>

In browser

Page 49: JS Lab`16. Сергей Селецкий: "Ретроспектива тестирования JavaScript"

JSLitmus var sys = require('sys'); var jslitmus = require('./jslitmus.js');

var a = new Array(10000); jslitmus.test('Join 10K elements', function() { a.join(' '); });

// Log the test results jslitmus.on('complete', function(test) { sys.log(test); });

// Run it! jslitmus.runAll();

In node.js

Page 50: JS Lab`16. Сергей Селецкий: "Ретроспектива тестирования JavaScript"

JSLitmus// Many developers are unaware how much influence the scope of a variable has // on script performance. To demonstrate this, we create the following // JSLitmus tests to measure how the "increment" operator performs when applied // to variables defined in different scopes

// First, test a variable in the global scope var global_var = 1; JSLitmus.test('global', function(count) { while (count--) global_var++;} );

// Now test one that's in a function's local scope JSLitmus.test('local', function(count) { var local_var = 1; while (count--) local_var++; });

// Try a variable bound to a closure function. Prototype and JQuery developers // should find this particularly interesting. JSLitmus.test('closure', (function() { var closure_var = 1; return function(count) {while (count--) closure_var++;} })() );

// Closure binding again, but this time with the variable bound through nested // closures. JSLitmus.test('multi-closure', (function() { var multi_var = 1; return (function() { return function(count) {while (count--) multi_var++;} })() })() );

Page 51: JS Lab`16. Сергей Селецкий: "Ретроспектива тестирования JavaScript"

BusterA powerful suite of automated test tools for JavaScript

A JavaScript test-runner built with Node.js. Very modular and flexible. It comes with it's own assertion library, but you can add your own if you like.

Main Features • Run tests from browser or headless with PhantomJS • Run on multiple clients at once • Don't need to run server/clients on development computer (no need for IE) • Run tests from command line (can be integrated in ant/maven) • Write tests xUnit or BDD style • Supports multiple JavaScript test frameworks • Defer tests instead of commenting them out • SinonJS built in • Auto-run tests on save • Proxies requests cross-domain • Possible to customize assertions, reporters • TextMate and Emacs integration

Mar 13, 2011 – Jan, 2016

https://github.com/busterjs/buster

Page 52: JS Lab`16. Сергей Селецкий: "Ретроспектива тестирования JavaScript"

Buster// This assertion does not exist! assert.notEquals(foo, bar);

// Instead: refute.equals(two, objects);

// And so on refute(false); refute.same(two, objects); refute.defined(something);

var buster = require("buster"); var assert = buster.referee.assert; var myLib = require("../lib/my-lib");

buster.testCase("A test case", { "test it": function () { assert(myLib.doIt()); } });

Page 53: JS Lab`16. Сергей Селецкий: "Ретроспектива тестирования JavaScript"

Buster$ buster-server buster-server running on http://localhost:1111

Open the browsers you want to run tests in and click the capture button.

First, start the server

Page 54: JS Lab`16. Сергей Селецкий: "Ретроспектива тестирования JavaScript"

Buster

$ buster-static Starting server on http://localhost:8282

Buster.JS also has a static browser runner that runs tests by opening a web page in a browser. This is similar to QUnit, Mocha

Page 55: JS Lab`16. Сергей Селецкий: "Ретроспектива тестирования JavaScript"

JestPainless JavaScript Unit Testing

May 11, 2014 – Mar, 2016

• Familiar Approach: Built on top of the Jasmine test framework, using familiar expect(value).toBe(other) assertions

• Mock by Default: Automatically mocks CommonJS modules returned by require(), making most existing code testable

• Short Feedback Loop (!): DOM APIs are mocked and tests run in parallel via a small node.js command line utility

Page 56: JS Lab`16. Сергей Селецкий: "Ретроспектива тестирования JavaScript"

Jestjest.unmock('../CheckboxWithLabel');

import React from 'react'; import ReactDOM from 'react-dom'; import TestUtils from 'react-addons-test-utils'; import CheckboxWithLabel from '../CheckboxWithLabel';

describe('CheckboxWithLabel', () => { it('changes the text after click', () => { // Render a checkbox with label in the document const checkbox = TestUtils.renderIntoDocument( <CheckboxWithLabel labelOn="On" labelOff="Off" /> );

const checkboxNode = ReactDOM.findDOMNode(checkbox);

// Verify that it's Off by default expect(checkboxNode.textContent).toEqual('Off');

// ... }); });

Page 57: JS Lab`16. Сергей Селецкий: "Ретроспектива тестирования JavaScript"

КАКИЕ ТЕНДЕНЦИИ

(ВОПРОСЫ К АУДИТОРИИ)

Page 58: JS Lab`16. Сергей Селецкий: "Ретроспектива тестирования JavaScript"

PRODUCTION TESTING

Page 59: JS Lab`16. Сергей Селецкий: "Ретроспектива тестирования JavaScript"

A/B TESTING

Page 60: JS Lab`16. Сергей Селецкий: "Ретроспектива тестирования JavaScript"

ГЕНЕРАЦИЯ ТЕСТОВ

RECORD/PLAY CODELESS TESTS

Page 61: JS Lab`16. Сергей Селецкий: "Ретроспектива тестирования JavaScript"

UI ДЛЯ СОЗДАНИЯ ТЕСТОВ

Page 62: JS Lab`16. Сергей Селецкий: "Ретроспектива тестирования JavaScript"

TIME TRAVEL TESTING

Page 63: JS Lab`16. Сергей Селецкий: "Ретроспектива тестирования JavaScript"

BIG DATA TESTING

Page 64: JS Lab`16. Сергей Селецкий: "Ретроспектива тестирования JavaScript"

INTERNET OF THINGSSO WHAT?

Page 65: JS Lab`16. Сергей Селецкий: "Ретроспектива тестирования JavaScript"

INTERNET OF THINGSSO WHAT? ——>API

Page 66: JS Lab`16. Сергей Селецкий: "Ретроспектива тестирования JavaScript"

ПРОВЕРКА АПЛОДИСМЕНТОВ

СПАСИБО

@SSELETSKYY

Page 67: JS Lab`16. Сергей Селецкий: "Ретроспектива тестирования JavaScript"