Webinar | Content
Unit tests UI tests
Continuous
Integration
• Writing a unit test
• Using PhantomJS
• Hello world sample
• Event recorder intro
• Testing an Ext JS cmp
• Recording a UI test
• TeamCity
• Code Coverage
• Statistics
• Cloud Testing
Slide 4
Slide 4 text
Intro | DESCRIPTION
Less Theory, More Real World
Slide 5
Slide 5 text
Intro | WHY
Why Testing?
Slide 6
Slide 6 text
Intro | WHY
Hands up: Who is testing their JS?
Slide 7
Slide 7 text
Intro | WHY
Slide 8
Slide 8 text
Intro | WHY
1. Productivity & confidence in code
2. Frameworks contain bugs
3. So does your code (and mine)
4. Refactoring & code handover
5. Fix bugs once
Slide 9
Slide 9 text
Intro | TERMINOLOGY
Terminology: what does testing mean for a JS developer?
Slide 10
Slide 10 text
Intro | TERMINOLOGY
Unit tests, UI tests, Application tests..?
Slide 11
Slide 11 text
Intro | TERMINOLOGY
Unit tests
App Tests
UI tests
Slide 12
Slide 12 text
Testing With Siesta
Introduction
Slide 13
Slide 13 text
Intro | Testing with Siesta
• runs in any browser
• is written in plain JS
• is sandboxed by default
A Siesta test…
Slide 14
Slide 14 text
Intro | Testing with Siesta
• can do both UI and unit testing
• can be automated using PhantomJS or Selenium WebDriver
• can detect leaked global variables
A Siesta test…
Slide 15
Slide 15 text
Intro | Testing with Siesta
describe('A simple Model test', function (t) {
t.it('Should do something', function(t) {
// Test things
t.expect(1).toBe(1);
});
});
Slide 16
Slide 16 text
Unit Tests
Red, Green, Refactor
Slide 17
Slide 17 text
Unit tests | Intro
•Unit tests usually only involve “raw” JS
•Run very fast
•Perfect for pre-commit hooks
•Disable sandboxing if possible
Slide 18
Slide 18 text
Unit tests | Intro
•Should be your #1 priority
•Cover your most important JS classes
•Run often, before commit, daily, nightly.
•Use TDD approach + BDD style for readability
Slide 19
Slide 19 text
Unit tests | TDD basics
1. Make the unit test fail
2. Implement
3. Make the test pass
4. Refactor, Repeat
Slide 20
Slide 20 text
Unit tests | Writing a unit test
Unit testing demo
Slide 21
Slide 21 text
Testing your UI
Functional testing
Slide 22
Slide 22 text
UI tests | Intro
Manually writing UI tests takes time
Slide 23
Slide 23 text
UI tests | Intro
UI tests are more fragile & run slower than unit tests
Slide 24
Slide 24 text
UI tests | Intro
Understanding CSS and ComponentQuery is key
Slide 25
Slide 25 text
UI tests | Intro
•UI “unit test” of a single UI component
•Or Application test, open index.html and test it
Two main types of UI tests
Slide 26
Slide 26 text
UI tests | Intro
UI Unit test demo
Slide 27
Slide 27 text
UI tests | Intro
Siesta Event Recorder
Slide 28
Slide 28 text
UI tests | Event recorder
•Great for application tests
•Records user actions: clicks, types, drag drop
•Exports actions to a Siesta test case
•Can be used by a non-programmer
•Big timesaver
Slide 29
Slide 29 text
UI tests | Event recorder
Let’s try the recorder
Slide 30
Slide 30 text
UI tests | Monkey tests
Monkey testing
Slide 31
Slide 31 text
UI tests | Monkey tests
•Random UI testing
•Clicks, drags etc. in your UI
•Finds unhandled exceptions
•Free testing help. 0€
UI tests | Cloud testing
So…running in multiple browsers?
Slide 37
Slide 37 text
Continuous Integration | Cloud testing
•Need to create Virtual Machines for each version of IE
•Total: Chrome, Safari, FF, IE 7-11 => 7 VMs
•Managing such a farm can be very time consuming
Slide 38
Slide 38 text
Continuous Integration | Cloud testing
•Siesta integrates with both BrowserStack and Sauce Labs
•Run tests easily in any OS and Browser combination
•No need to setup your own VM farm
•Read more on the Bryntum blog…
Slide 39
Slide 39 text
Continuous Integration | Cloud testing
Launching tests in BrowserStack
Slide 40
Slide 40 text
Rounding up | Links
•bryntum.com/products/siesta
•bryntum.com/docs/siesta
•teamcity.bryntum.com/guest
•browserstack.com/
•saucelabs.com/
Slide 41
Slide 41 text
Rounding up | Questions
Questions?
Twitter: @Bryntum