SlideShare a Scribd company logo
UI Testing, handling
complex UIs at scale
Josh Black :: FEDucation :: March 2nd, 2016
.FED@IBM
Discussion Time 

A look at the landscape of testing
options and techniques for
developers.
.FED@IBM
Wikipedia 

An investigation conducted to
provide information about the quality
of a product or service under test.
.FED@IBM
Testing

Helps developers tell whether
the product is working or not.
.FED@IBM
Overview
The Basics
What are the various kinds of tests? How do I know when to
use each one?
Writing a Test
How can we structure our tests in a way that's clean, readable,
and effective?
Real World
What kind of tools can I leverage to start testing in my project
today?
0
Part 0 

Setting the Stage
What is a test?
.FED@IBM
Testing 

When a developer changes a piece
of code in a project, how confident
am I that sh*t won't break?
.FED@IBM
Testing a Dropdown
class Dropdown {
/* ... */
}
const d = new Dropdown({
items: ['Home', 'Cognitive', 'Watson', 'Services'],
defaultText: 'Please select an item',
target: document.querySelector('.dropdown')
});
.FED@IBM
HTML
<ul class="dropdown">
<li class="dropdown__item">
<p id="current">Please select an item</p>
<span class="dropdown__arrow"></span>
<ul class="dropdown-menu">
<li class="dropdown-menu__item"><a href="#">Home</a></li>
<li class="dropdown-menu__item"><a href="#cognitive">Cognitive</a></li>
<li class="dropdown-menu__item"><a href="#watson">Watson</a></li>
<li class="dropdown-menu__item"><a href="#services">Services</a></li>
</ul>
</li>
</ul>
.FED@IBM
JavaScript
const d = new Dropdown({
items: ['Home', 'Cognitive', 'Watson', 'Services'],
defaultText: 'Please select an item',
target: document.querySelector('.dropdown')
});
dropdown.arrow.addEventListener('click', () => {
dropdown.classList.toggle('is-expanded');
});
.FED@IBM
UI Testing
.FED@IBM
.FED@IBM
UI Testing
Testing 

Allows us to make a trade-off
between reliability and speed.
.FED@IBM
Testing a Dropdown
class Dropdown {
/* ... */
}
const d = new Dropdown({
items: ['Home', 'Cognitive', 'Watson', 'Services'],
defaultText: 'Please select an item',
target: document.querySelector('.dropdown')
});
.FED@IBM
Testing a Dropdown
describe('Dropdown', () => {
it('should ...', () => {
// ...
});
});
.FED@IBM
Testing a Dropdown
describe('Dropdown', () => {
it('should expand the list of options when clicked', () => {
// ...
});
});
.FED@IBM
Testing a Dropdown
describe('Dropdown', () => {
it('should expand the list of options when clicked', () => {
// ...
});
it('should collapse the list of options when an item is selected', () => {
// ...
});
});
.FED@IBM
Test-Driven Development
Test Behavior-Driven
Development
Add some initial,
failing tests
Add Tests
.FED@IBM
Write an initial attempt at
making your test pass
Write code
.FED@IBM
Run tests, re-working
until they go green
Run Tests
.FED@IBM
Now that you have passing
tests, go back and refine
Refactor
.FED@IBM
Unit Tests
Allows us to test small pieces of functionality in
isolation.
Integration Tests
End-to-End Tests
Understand and test how a user
flows through the system
Test the integration of small pieces of
functionality with each other
Testing

Basic Types
.FED@IBM
Unit Tests
const addIntegers = (a, b) => a + b;
describe('add', () => {
it('should add two integers together', () => {
const a = 1;
const b = 2;
expect(add(a, b)).toBe(a + b); // true || false
});
});
.FED@IBM
Unit Tests
const addIntegers = (a, b) => a + b;
addIntegers(1.5, 'a'); // 1.5a
.FED@IBM
Unit Tests
const addIntegers = (a, b) => {
const { isInteger } = Number;
invariant(
isInteger(a) && isInteger(b),
'Expected integer arguments, instead got: [%s, %s]',
a, b
);
return a + b;
}
.FED@IBM
Unit Tests
const addIntegers = (a, b) => /* ... */
describe('add', () => {
it('should warn if an argument is not an integer', () => {
const a = 1;
const b = 'a';
expect(add(a, b)).toThrow();
});
});
.FED@IBM
Integration Tests
Scenario
.FED@IBM
Visualization
API Response Validation
Duration
Count Visualization
Scenario
.FED@IBM
Validation
Duration
Count
Scenario
.FED@IBM
Validation
Duration
Count
Testing a Validator
describe('Validator', () => {
it('should validate a response from our API', () => {
// ...
});
});
.FED@IBM
Testing getDuration
describe('getDuration', () => {
it('should get a duration value from an API response', () => {
// ...
});
});
.FED@IBM
Integration Test
import Validator from '../Validator';
import getDuration from '../getDuration';
describe('getResponseDuration', () => {
it('should get a duration value from an API response', () => {
const response = {};
const validated = Validator(response);
expect(validated.passed).toBe(true);
expect(validated.value).toBe(response.result.data);
// ...
});
});
.FED@IBM
Integration Test
describe('getResponseDuration', () => {
it('should get a duration value from an API response', () => {
const response = {};
const validated = Validator(response);
expect(validated.passed).toBe(true);
expect(validated.value).toBe(response.result.data);
const durationCount = getDuration(validated.value);
expect(durationCount).toBe(300);
});
});
.FED@IBM
End-to-End Tests
E2E 

Focus on real user scenarios,
catching bugs before they reach the
user.
.FED@IBM
E2E Scenario
.FED@IBM
Hits EnterLogin Form Clicks Form Enter Credentials
Testing Pyramid
.FED@IBM
E2E
Integration
Unit
Testing Pyramid
.FED@IBM
E2E
Integration
Unit
Unit Testing
Allows us to create a fast, reliable
feedback loop that isolates errors.
Requirements:
Knowledge in areas such as dependency
management, mocking, and hermetic
testing.
Testing Pyramid
.FED@IBM
E2E
Integration
Unit
Integration Tests
Allows us to verify the behavior of
small groups of units
Testing Pyramid
.FED@IBM
E2E
Integration
Unit
End-to-End Tests
Covers a small set of our product
features to help catch bugs that may
reach customers
Take a Look Just Say No More to End-to-End Tests
Covers the practicality of E2E tests, highlighting the
advantages of favoring unit/integration tests over E2E.
Move Fast and Don't Break Things
Discusses the integration and role of testing in the context of
Continuous Integration and Delivery
Link
Link
Part 1 

Writing a test
.FED@IBM
How to actually get started
Setup 

Test runners, assertions, and
spies, oh my!
.FED@IBM
mocha
chai
karma
expect
expect.js
jasmine
sinon
qunit
selenium
web driver
ava
jsdom
.FED@IBM
Test Runner
Allows us to write chunks of code to describe
what should happen. Handles executing tests
for us and returning the result.
Assertion Library
Spies
Sometimes we need to check and verify that
what we think will be called is actually called
Enables us to state what we believe to be
true, false, and a variety of other states.
Testing

Checklist
.FED@IBM
Test Runner
Allows us to write chunks of code to describe
what should happen. Handles executing tests
for us and returning the result.
Assertion Library
Spies
Sometimes we need to check and verify that
what we think will be called is actually called
Enables us to state what we believe to be
true, false, and a variety of other states.
Testing

Checklist
.FED@IBM
DOM Mocking / Driver
Allows us to verify that what we expect to
happen in our product is actually happening
Test Runner
describe('Module', () => {
it('should ...', () => {
// ...
});
});
.FED@IBM
Test Runner
.FED@IBM
Take a Look Mocha
Classic JavaScript test framework for JavaScript
Jasmine
DOM-less simple JavaScript Testing Framework
https://www.npmjs.com/package/mocha
https://www.npmjs.com/package/jasmine
Karma
Spectacular Test Runner for JavaScript
https://www.npmjs.com/package/karma
Ava
Futuristic Test Runner for JavaScript
https://www.npmjs.com/package/ava
Assertions
Assertions 

Specify what you expect the
outcome of a scenario to be.
.FED@IBM
Assertions
describe('Module', () => {
it('should ...', () => {
const result = Module();
expect(result).toBe(2);
});
});
.FED@IBM
Assertions
describe('Module', () => {
it('should ...', () => {
const result = Module();
expect(result).toEqual({
title: 'FEDucation',
description: 'Coolest FED gathering in the world'
});
});
});
.FED@IBM
Assertions
describe('Module', () => {
it('should ...', () => {
const result = Module();
expect(result).toEqual(['some', 'collection']);
});
});
.FED@IBM
Assertions
describe('Module', () => {
it('should ...', () => {
const result = Module();
expect(result).toThrow();
});
});
.FED@IBM
Assertions
describe('Module', () => {
it('should ...', () => {
const result = Module();
expect(result).to.be.instanceOf(Error);
});
});
.FED@IBM
Assertions
it('supports loading multiple keys in one call', async () => {
var identityLoader = new DataLoader(keys => Promise.resolve(keys));
var promiseAll = identityLoader.loadMany([ 1, 2 ]);
expect(promiseAll).to.be.instanceof(Promise);
var values = await promiseAll;
expect(values).to.deep.equal([ 1, 2 ]);
var promiseEmpty = identityLoader.loadMany([]);
expect(promiseEmpty).to.be.instanceof(Promise);
var empty = await promiseEmpty;
expect(empty).to.deep.equal([]);
});
.FED@IBM
Take a Look Expect
Write better assertions
Chai
BDD/TDD assertion library for node.js and the browser
https://www.npmjs.com/package/expect
https://www.npmjs.com/package/chai
Should
Test framework agnostic BDD-style assertions
https://www.npmjs.com/package/should
Assert
Native assertion library for Node.js
Spies
Spies 

Stubs out any function and tracks
calls to it and all arguments
.FED@IBM
Assertions
const sum = (a, b) => a + b;
describe('A spy', () => {
it('should track that the spy was called', () => {
spyOn(sum);
sum(1, 2);
expect(sum).toHaveBeenCalled();
expect(sum).toHaveBeenCalledWith(1, 2);
});
});
.FED@IBM
Assertions
describe('Module', () => {
it('should track that the spy was called', () => {
spyOn(console, 'error');
const result = Module('invalid argument');
expect(console.error).toHaveBeenCalled();
expect(console.error)
.toHaveBeenCalledWith('invalid argument');
});
});
.FED@IBM
Isolation
Achieves similar results to mocks, stubs,
dummies, fakes, etc for accomplishing isolation
Consistent Interface
Partial Mocking
You as the developer choose what portions
of an interface you want to mock
Spies follow the same interface as the
functions that they're mocking
Spies

Highlights
.FED@IBM
Take a Look Jasmine
DOM-less simple JavaScript Testing Framework
Expect
Write better assertions
Sinon
JavaScript test spies, stubs and mocks
https://www.npmjs.com/package/sinon
DOM Mocking
End-to-End
Tests
Prohibitively Expensive
Loading up the browser, and performing a multitude of tests
doesn't fit our ideal feedback loop for testing.
Flakiness
Race conditions, or other processes that may yield
inconsistent results for a test due to using the DOM.
Tooling
In the past, we'd have to use complex tool chains like Selenium
with Web Driver just to get E2E that don't actually help us, or
the user.
Take a Look jsdom
A JavaScript implementation of the DOM and HTMl standards
Karma
Brings a productive testing environment to developers
https://www.npmjs.com/package/jsdom
https://www.npmjs.com/package/karma
Selenium Web Driver
Driving a browser natively as a user would
http://docs.seleniumhq.org/projects/webdriver/
DOM Mocking
import jsdom from 'mocha-jsdom';
import { expect } from 'chai';
describe('mocha tests', function () {
jsdom()
it('has document', function () {
var div = document.createElement('div')
expect(div.nodeName).eql('DIV')
});
});
.FED@IBM
DOM Mocking
it('should work for DOM events', function () {
var div = document.createElement('div');
div.addEventListener('click', () => console.log('FEDs rule!'));
spyOn(console, 'log');
div.click();
expect(console.log).toHaveBeenCalled();
expect(console.log).toHaveBeenCalledWith('FEDs rule!');
});
.FED@IBM
DOM Mocking
import jsdom from 'mocha-jsdom';
import { expect } from 'chai';
const markup = '<html>...</html>';
describe('mocha tests', function () {
jsdom(markup)
it('has document', function () {
var app = document.querySelector('#app')
expect(app.nodeName).eql('DIV')
});
});
.FED@IBM
Recap The Basics
Overview of Unit, Integration, and End-to-End tests.
The Tools
Identify the necessary components that developers need for a
robust testing framework.
The Practice
How do we go about structuring our tests, and begin writing
tests using the techniques/testing frameworks that we've
identified0
Google 

Focus on the user and all else
will follow
.FED@IBM
Testing 

Enables us to move fast and
not break things
.FED@IBM
@joshblackfr
github.com/joshblack
github.ibm.com/joshblack
Thanks!
Any Questions?
Ad

More Related Content

What's hot (19)

Coldbox developer training – session 4
Coldbox developer training – session 4Coldbox developer training – session 4
Coldbox developer training – session 4
Billie Berzinskas
 
Principles and patterns for test driven development
Principles and patterns for test driven developmentPrinciples and patterns for test driven development
Principles and patterns for test driven development
Stephen Fuqua
 
Test Automation Frameworks Final
Test Automation Frameworks   FinalTest Automation Frameworks   Final
Test Automation Frameworks Final
Margaret_Dickman
 
RFT Tutorial - 9 How To Create A Properties Verification Point In Rft For Tes...
RFT Tutorial - 9 How To Create A Properties Verification Point In Rft For Tes...RFT Tutorial - 9 How To Create A Properties Verification Point In Rft For Tes...
RFT Tutorial - 9 How To Create A Properties Verification Point In Rft For Tes...
Yogindernath Gupta
 
Xam expertday
Xam expertdayXam expertday
Xam expertday
Codrina Merigo
 
AD208 - End to End Quality Processes for Top Notch XPages Apps
AD208 - End to End Quality Processes for Top Notch XPages AppsAD208 - End to End Quality Processes for Top Notch XPages Apps
AD208 - End to End Quality Processes for Top Notch XPages Apps
beglee
 
Top Testing Tips
Top Testing TipsTop Testing Tips
Top Testing Tips
Salesforce Developers
 
Angular Unit Testing
Angular Unit TestingAngular Unit Testing
Angular Unit Testing
Alessandro Giorgetti
 
Don't Be Mocked by your Mocks - Best Practices using Mocks
Don't Be Mocked by your Mocks - Best Practices using MocksDon't Be Mocked by your Mocks - Best Practices using Mocks
Don't Be Mocked by your Mocks - Best Practices using Mocks
Victor Rentea
 
Testing using load runner performance testing
Testing using load runner  performance testingTesting using load runner  performance testing
Testing using load runner performance testing
SivaprasanthRentala1975
 
Enterprise java beans(ejb)
Enterprise java beans(ejb)Enterprise java beans(ejb)
Enterprise java beans(ejb)
vikram singh
 
Enterprise java beans(ejb) update 2
Enterprise java beans(ejb) update 2Enterprise java beans(ejb) update 2
Enterprise java beans(ejb) update 2
vikram singh
 
Working Effectively With Legacy Code
Working Effectively With Legacy CodeWorking Effectively With Legacy Code
Working Effectively With Legacy Code
scidept
 
Code Quality Practice and Tools
Code Quality Practice and ToolsCode Quality Practice and Tools
Code Quality Practice and Tools
Bob Paulin
 
Effective JavaFX architecture with FxObjects
Effective JavaFX architecture with FxObjectsEffective JavaFX architecture with FxObjects
Effective JavaFX architecture with FxObjects
Srikanth Shenoy
 
Fitnesse Testing Framework
Fitnesse Testing Framework Fitnesse Testing Framework
Fitnesse Testing Framework
Ajit Koti
 
Gett - Mobile automation 2015
Gett - Mobile automation 2015Gett - Mobile automation 2015
Gett - Mobile automation 2015
adi ben aroya
 
Basics of Spring - KNOWARTH
Basics of Spring - KNOWARTHBasics of Spring - KNOWARTH
Basics of Spring - KNOWARTH
KNOWARTH Technologies
 
Google mock for dummies
Google mock for dummiesGoogle mock for dummies
Google mock for dummies
Harry Potter
 
Coldbox developer training – session 4
Coldbox developer training – session 4Coldbox developer training – session 4
Coldbox developer training – session 4
Billie Berzinskas
 
Principles and patterns for test driven development
Principles and patterns for test driven developmentPrinciples and patterns for test driven development
Principles and patterns for test driven development
Stephen Fuqua
 
Test Automation Frameworks Final
Test Automation Frameworks   FinalTest Automation Frameworks   Final
Test Automation Frameworks Final
Margaret_Dickman
 
RFT Tutorial - 9 How To Create A Properties Verification Point In Rft For Tes...
RFT Tutorial - 9 How To Create A Properties Verification Point In Rft For Tes...RFT Tutorial - 9 How To Create A Properties Verification Point In Rft For Tes...
RFT Tutorial - 9 How To Create A Properties Verification Point In Rft For Tes...
Yogindernath Gupta
 
AD208 - End to End Quality Processes for Top Notch XPages Apps
AD208 - End to End Quality Processes for Top Notch XPages AppsAD208 - End to End Quality Processes for Top Notch XPages Apps
AD208 - End to End Quality Processes for Top Notch XPages Apps
beglee
 
Don't Be Mocked by your Mocks - Best Practices using Mocks
Don't Be Mocked by your Mocks - Best Practices using MocksDon't Be Mocked by your Mocks - Best Practices using Mocks
Don't Be Mocked by your Mocks - Best Practices using Mocks
Victor Rentea
 
Testing using load runner performance testing
Testing using load runner  performance testingTesting using load runner  performance testing
Testing using load runner performance testing
SivaprasanthRentala1975
 
Enterprise java beans(ejb)
Enterprise java beans(ejb)Enterprise java beans(ejb)
Enterprise java beans(ejb)
vikram singh
 
Enterprise java beans(ejb) update 2
Enterprise java beans(ejb) update 2Enterprise java beans(ejb) update 2
Enterprise java beans(ejb) update 2
vikram singh
 
Working Effectively With Legacy Code
Working Effectively With Legacy CodeWorking Effectively With Legacy Code
Working Effectively With Legacy Code
scidept
 
Code Quality Practice and Tools
Code Quality Practice and ToolsCode Quality Practice and Tools
Code Quality Practice and Tools
Bob Paulin
 
Effective JavaFX architecture with FxObjects
Effective JavaFX architecture with FxObjectsEffective JavaFX architecture with FxObjects
Effective JavaFX architecture with FxObjects
Srikanth Shenoy
 
Fitnesse Testing Framework
Fitnesse Testing Framework Fitnesse Testing Framework
Fitnesse Testing Framework
Ajit Koti
 
Gett - Mobile automation 2015
Gett - Mobile automation 2015Gett - Mobile automation 2015
Gett - Mobile automation 2015
adi ben aroya
 
Google mock for dummies
Google mock for dummiesGoogle mock for dummies
Google mock for dummies
Harry Potter
 

Similar to UI Testing (20)

Pragmatic Parallels: Java and JavaScript
Pragmatic Parallels: Java and JavaScriptPragmatic Parallels: Java and JavaScript
Pragmatic Parallels: Java and JavaScript
davejohnson
 
Acceptance Testing With Selenium
Acceptance Testing With SeleniumAcceptance Testing With Selenium
Acceptance Testing With Selenium
elliando dias
 
Test driven development in .Net - 2010 + Eclipse
Test driven development in .Net - 2010 + EclipseTest driven development in .Net - 2010 + Eclipse
Test driven development in .Net - 2010 + Eclipse
UTC Fire & Security
 
Justmeans power point
Justmeans power pointJustmeans power point
Justmeans power point
justmeanscsr
 
Grails unit testing
Grails unit testingGrails unit testing
Grails unit testing
pleeps
 
Java script unit testing
Java script unit testingJava script unit testing
Java script unit testing
Mats Bryntse
 
Getting Started With Testing
Getting Started With TestingGetting Started With Testing
Getting Started With Testing
Giovanni Scerra ☃
 
Testing in Craft CMS
Testing in Craft CMSTesting in Craft CMS
Testing in Craft CMS
JustinHolt20
 
Test Drive Development in Ruby On Rails
Test Drive Development in Ruby On RailsTest Drive Development in Ruby On Rails
Test Drive Development in Ruby On Rails
Nyros Technologies
 
GlobalLogic Test Automation Online TechTalk “Test Driven Development as a Per...
GlobalLogic Test Automation Online TechTalk “Test Driven Development as a Per...GlobalLogic Test Automation Online TechTalk “Test Driven Development as a Per...
GlobalLogic Test Automation Online TechTalk “Test Driven Development as a Per...
GlobalLogic Ukraine
 
Tdd is not about testing (OOP)
Tdd is not about testing (OOP)Tdd is not about testing (OOP)
Tdd is not about testing (OOP)
Gianluca Padovani
 
In search of JavaScript code quality: unit testing
In search of JavaScript code quality: unit testingIn search of JavaScript code quality: unit testing
In search of JavaScript code quality: unit testing
Anna Khabibullina
 
Unit Testing and Coverage for AngularJS
Unit Testing and Coverage for AngularJSUnit Testing and Coverage for AngularJS
Unit Testing and Coverage for AngularJS
Knoldus Inc.
 
3 Ways to test your ColdFusion API - 2017 Adobe CF Summit
3 Ways to test your ColdFusion API - 2017 Adobe CF Summit3 Ways to test your ColdFusion API - 2017 Adobe CF Summit
3 Ways to test your ColdFusion API - 2017 Adobe CF Summit
Ortus Solutions, Corp
 
Behavior Driven Development by Example
Behavior Driven Development by ExampleBehavior Driven Development by Example
Behavior Driven Development by Example
Nalin Goonawardana
 
Test & behavior driven development
Test & behavior driven developmentTest & behavior driven development
Test & behavior driven development
Tristan Libersat
 
Coding Naked 2023
Coding Naked 2023Coding Naked 2023
Coding Naked 2023
Caleb Jenkins
 
Javascript unit testing, yes we can e big
Javascript unit testing, yes we can   e bigJavascript unit testing, yes we can   e big
Javascript unit testing, yes we can e big
Andy Peterson
 
Unit Testing in Flutter - From Workflow Essentials to Complex Scenarios
Unit Testing in Flutter - From Workflow Essentials to Complex ScenariosUnit Testing in Flutter - From Workflow Essentials to Complex Scenarios
Unit Testing in Flutter - From Workflow Essentials to Complex Scenarios
RubenGray1
 
An introduction to unit testing
An introduction to unit testingAn introduction to unit testing
An introduction to unit testing
Adam Stephensen
 
Pragmatic Parallels: Java and JavaScript
Pragmatic Parallels: Java and JavaScriptPragmatic Parallels: Java and JavaScript
Pragmatic Parallels: Java and JavaScript
davejohnson
 
Acceptance Testing With Selenium
Acceptance Testing With SeleniumAcceptance Testing With Selenium
Acceptance Testing With Selenium
elliando dias
 
Test driven development in .Net - 2010 + Eclipse
Test driven development in .Net - 2010 + EclipseTest driven development in .Net - 2010 + Eclipse
Test driven development in .Net - 2010 + Eclipse
UTC Fire & Security
 
Justmeans power point
Justmeans power pointJustmeans power point
Justmeans power point
justmeanscsr
 
Grails unit testing
Grails unit testingGrails unit testing
Grails unit testing
pleeps
 
Java script unit testing
Java script unit testingJava script unit testing
Java script unit testing
Mats Bryntse
 
Testing in Craft CMS
Testing in Craft CMSTesting in Craft CMS
Testing in Craft CMS
JustinHolt20
 
Test Drive Development in Ruby On Rails
Test Drive Development in Ruby On RailsTest Drive Development in Ruby On Rails
Test Drive Development in Ruby On Rails
Nyros Technologies
 
GlobalLogic Test Automation Online TechTalk “Test Driven Development as a Per...
GlobalLogic Test Automation Online TechTalk “Test Driven Development as a Per...GlobalLogic Test Automation Online TechTalk “Test Driven Development as a Per...
GlobalLogic Test Automation Online TechTalk “Test Driven Development as a Per...
GlobalLogic Ukraine
 
Tdd is not about testing (OOP)
Tdd is not about testing (OOP)Tdd is not about testing (OOP)
Tdd is not about testing (OOP)
Gianluca Padovani
 
In search of JavaScript code quality: unit testing
In search of JavaScript code quality: unit testingIn search of JavaScript code quality: unit testing
In search of JavaScript code quality: unit testing
Anna Khabibullina
 
Unit Testing and Coverage for AngularJS
Unit Testing and Coverage for AngularJSUnit Testing and Coverage for AngularJS
Unit Testing and Coverage for AngularJS
Knoldus Inc.
 
3 Ways to test your ColdFusion API - 2017 Adobe CF Summit
3 Ways to test your ColdFusion API - 2017 Adobe CF Summit3 Ways to test your ColdFusion API - 2017 Adobe CF Summit
3 Ways to test your ColdFusion API - 2017 Adobe CF Summit
Ortus Solutions, Corp
 
Behavior Driven Development by Example
Behavior Driven Development by ExampleBehavior Driven Development by Example
Behavior Driven Development by Example
Nalin Goonawardana
 
Test & behavior driven development
Test & behavior driven developmentTest & behavior driven development
Test & behavior driven development
Tristan Libersat
 
Javascript unit testing, yes we can e big
Javascript unit testing, yes we can   e bigJavascript unit testing, yes we can   e big
Javascript unit testing, yes we can e big
Andy Peterson
 
Unit Testing in Flutter - From Workflow Essentials to Complex Scenarios
Unit Testing in Flutter - From Workflow Essentials to Complex ScenariosUnit Testing in Flutter - From Workflow Essentials to Complex Scenarios
Unit Testing in Flutter - From Workflow Essentials to Complex Scenarios
RubenGray1
 
An introduction to unit testing
An introduction to unit testingAn introduction to unit testing
An introduction to unit testing
Adam Stephensen
 
Ad

Recently uploaded (20)

Get & Download Wondershare Filmora Crack Latest [2025]
Get & Download Wondershare Filmora Crack Latest [2025]Get & Download Wondershare Filmora Crack Latest [2025]
Get & Download Wondershare Filmora Crack Latest [2025]
saniaaftab72555
 
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
Andre Hora
 
PDF Reader Pro Crack Latest Version FREE Download 2025
PDF Reader Pro Crack Latest Version FREE Download 2025PDF Reader Pro Crack Latest Version FREE Download 2025
PDF Reader Pro Crack Latest Version FREE Download 2025
mu394968
 
Microsoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdf
Microsoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdfMicrosoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdf
Microsoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdf
TechSoup
 
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage DashboardsAdobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
BradBedford3
 
Adobe Master Collection CC Crack Advance Version 2025
Adobe Master Collection CC Crack Advance Version 2025Adobe Master Collection CC Crack Advance Version 2025
Adobe Master Collection CC Crack Advance Version 2025
kashifyounis067
 
Adobe After Effects Crack FREE FRESH version 2025
Adobe After Effects Crack FREE FRESH version 2025Adobe After Effects Crack FREE FRESH version 2025
Adobe After Effects Crack FREE FRESH version 2025
kashifyounis067
 
Adobe Lightroom Classic Crack FREE Latest link 2025
Adobe Lightroom Classic Crack FREE Latest link 2025Adobe Lightroom Classic Crack FREE Latest link 2025
Adobe Lightroom Classic Crack FREE Latest link 2025
kashifyounis067
 
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRYLEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
NidaFarooq10
 
FL Studio Producer Edition Crack 2025 Full Version
FL Studio Producer Edition Crack 2025 Full VersionFL Studio Producer Edition Crack 2025 Full Version
FL Studio Producer Edition Crack 2025 Full Version
tahirabibi60507
 
Who Watches the Watchmen (SciFiDevCon 2025)
Who Watches the Watchmen (SciFiDevCon 2025)Who Watches the Watchmen (SciFiDevCon 2025)
Who Watches the Watchmen (SciFiDevCon 2025)
Allon Mureinik
 
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
Egor Kaleynik
 
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Eric D. Schabell
 
EASEUS Partition Master Crack + License Code
EASEUS Partition Master Crack + License CodeEASEUS Partition Master Crack + License Code
EASEUS Partition Master Crack + License Code
aneelaramzan63
 
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Dele Amefo
 
Automation Techniques in RPA - UiPath Certificate
Automation Techniques in RPA - UiPath CertificateAutomation Techniques in RPA - UiPath Certificate
Automation Techniques in RPA - UiPath Certificate
VICTOR MAESTRE RAMIREZ
 
Scaling GraphRAG: Efficient Knowledge Retrieval for Enterprise AI
Scaling GraphRAG:  Efficient Knowledge Retrieval for Enterprise AIScaling GraphRAG:  Efficient Knowledge Retrieval for Enterprise AI
Scaling GraphRAG: Efficient Knowledge Retrieval for Enterprise AI
danshalev
 
Douwan Crack 2025 new verson+ License code
Douwan Crack 2025 new verson+ License codeDouwan Crack 2025 new verson+ License code
Douwan Crack 2025 new verson+ License code
aneelaramzan63
 
Avast Premium Security Crack FREE Latest Version 2025
Avast Premium Security Crack FREE Latest Version 2025Avast Premium Security Crack FREE Latest Version 2025
Avast Premium Security Crack FREE Latest Version 2025
mu394968
 
The Significance of Hardware in Information Systems.pdf
The Significance of Hardware in Information Systems.pdfThe Significance of Hardware in Information Systems.pdf
The Significance of Hardware in Information Systems.pdf
drewplanas10
 
Get & Download Wondershare Filmora Crack Latest [2025]
Get & Download Wondershare Filmora Crack Latest [2025]Get & Download Wondershare Filmora Crack Latest [2025]
Get & Download Wondershare Filmora Crack Latest [2025]
saniaaftab72555
 
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
Andre Hora
 
PDF Reader Pro Crack Latest Version FREE Download 2025
PDF Reader Pro Crack Latest Version FREE Download 2025PDF Reader Pro Crack Latest Version FREE Download 2025
PDF Reader Pro Crack Latest Version FREE Download 2025
mu394968
 
Microsoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdf
Microsoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdfMicrosoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdf
Microsoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdf
TechSoup
 
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage DashboardsAdobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
BradBedford3
 
Adobe Master Collection CC Crack Advance Version 2025
Adobe Master Collection CC Crack Advance Version 2025Adobe Master Collection CC Crack Advance Version 2025
Adobe Master Collection CC Crack Advance Version 2025
kashifyounis067
 
Adobe After Effects Crack FREE FRESH version 2025
Adobe After Effects Crack FREE FRESH version 2025Adobe After Effects Crack FREE FRESH version 2025
Adobe After Effects Crack FREE FRESH version 2025
kashifyounis067
 
Adobe Lightroom Classic Crack FREE Latest link 2025
Adobe Lightroom Classic Crack FREE Latest link 2025Adobe Lightroom Classic Crack FREE Latest link 2025
Adobe Lightroom Classic Crack FREE Latest link 2025
kashifyounis067
 
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRYLEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
NidaFarooq10
 
FL Studio Producer Edition Crack 2025 Full Version
FL Studio Producer Edition Crack 2025 Full VersionFL Studio Producer Edition Crack 2025 Full Version
FL Studio Producer Edition Crack 2025 Full Version
tahirabibi60507
 
Who Watches the Watchmen (SciFiDevCon 2025)
Who Watches the Watchmen (SciFiDevCon 2025)Who Watches the Watchmen (SciFiDevCon 2025)
Who Watches the Watchmen (SciFiDevCon 2025)
Allon Mureinik
 
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
Egor Kaleynik
 
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Eric D. Schabell
 
EASEUS Partition Master Crack + License Code
EASEUS Partition Master Crack + License CodeEASEUS Partition Master Crack + License Code
EASEUS Partition Master Crack + License Code
aneelaramzan63
 
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Dele Amefo
 
Automation Techniques in RPA - UiPath Certificate
Automation Techniques in RPA - UiPath CertificateAutomation Techniques in RPA - UiPath Certificate
Automation Techniques in RPA - UiPath Certificate
VICTOR MAESTRE RAMIREZ
 
Scaling GraphRAG: Efficient Knowledge Retrieval for Enterprise AI
Scaling GraphRAG:  Efficient Knowledge Retrieval for Enterprise AIScaling GraphRAG:  Efficient Knowledge Retrieval for Enterprise AI
Scaling GraphRAG: Efficient Knowledge Retrieval for Enterprise AI
danshalev
 
Douwan Crack 2025 new verson+ License code
Douwan Crack 2025 new verson+ License codeDouwan Crack 2025 new verson+ License code
Douwan Crack 2025 new verson+ License code
aneelaramzan63
 
Avast Premium Security Crack FREE Latest Version 2025
Avast Premium Security Crack FREE Latest Version 2025Avast Premium Security Crack FREE Latest Version 2025
Avast Premium Security Crack FREE Latest Version 2025
mu394968
 
The Significance of Hardware in Information Systems.pdf
The Significance of Hardware in Information Systems.pdfThe Significance of Hardware in Information Systems.pdf
The Significance of Hardware in Information Systems.pdf
drewplanas10
 
Ad

UI Testing

  • 1. UI Testing, handling complex UIs at scale Josh Black :: FEDucation :: March 2nd, 2016 .FED@IBM
  • 2. Discussion Time 
 A look at the landscape of testing options and techniques for developers. .FED@IBM
  • 3. Wikipedia 
 An investigation conducted to provide information about the quality of a product or service under test. .FED@IBM
  • 4. Testing
 Helps developers tell whether the product is working or not. .FED@IBM
  • 5. Overview The Basics What are the various kinds of tests? How do I know when to use each one? Writing a Test How can we structure our tests in a way that's clean, readable, and effective? Real World What kind of tools can I leverage to start testing in my project today?
  • 6. 0 Part 0 
 Setting the Stage What is a test? .FED@IBM
  • 7. Testing 
 When a developer changes a piece of code in a project, how confident am I that sh*t won't break? .FED@IBM
  • 8. Testing a Dropdown class Dropdown { /* ... */ } const d = new Dropdown({ items: ['Home', 'Cognitive', 'Watson', 'Services'], defaultText: 'Please select an item', target: document.querySelector('.dropdown') }); .FED@IBM
  • 9. HTML <ul class="dropdown"> <li class="dropdown__item"> <p id="current">Please select an item</p> <span class="dropdown__arrow"></span> <ul class="dropdown-menu"> <li class="dropdown-menu__item"><a href="#">Home</a></li> <li class="dropdown-menu__item"><a href="#cognitive">Cognitive</a></li> <li class="dropdown-menu__item"><a href="#watson">Watson</a></li> <li class="dropdown-menu__item"><a href="#services">Services</a></li> </ul> </li> </ul> .FED@IBM
  • 10. JavaScript const d = new Dropdown({ items: ['Home', 'Cognitive', 'Watson', 'Services'], defaultText: 'Please select an item', target: document.querySelector('.dropdown') }); dropdown.arrow.addEventListener('click', () => { dropdown.classList.toggle('is-expanded'); }); .FED@IBM
  • 15. Testing 
 Allows us to make a trade-off between reliability and speed. .FED@IBM
  • 16. Testing a Dropdown class Dropdown { /* ... */ } const d = new Dropdown({ items: ['Home', 'Cognitive', 'Watson', 'Services'], defaultText: 'Please select an item', target: document.querySelector('.dropdown') }); .FED@IBM
  • 17. Testing a Dropdown describe('Dropdown', () => { it('should ...', () => { // ... }); }); .FED@IBM
  • 18. Testing a Dropdown describe('Dropdown', () => { it('should expand the list of options when clicked', () => { // ... }); }); .FED@IBM
  • 19. Testing a Dropdown describe('Dropdown', () => { it('should expand the list of options when clicked', () => { // ... }); it('should collapse the list of options when an item is selected', () => { // ... }); }); .FED@IBM
  • 22. Add some initial, failing tests Add Tests .FED@IBM
  • 23. Write an initial attempt at making your test pass Write code .FED@IBM
  • 24. Run tests, re-working until they go green Run Tests .FED@IBM
  • 25. Now that you have passing tests, go back and refine Refactor .FED@IBM
  • 26. Unit Tests Allows us to test small pieces of functionality in isolation. Integration Tests End-to-End Tests Understand and test how a user flows through the system Test the integration of small pieces of functionality with each other Testing
 Basic Types .FED@IBM
  • 27. Unit Tests const addIntegers = (a, b) => a + b; describe('add', () => { it('should add two integers together', () => { const a = 1; const b = 2; expect(add(a, b)).toBe(a + b); // true || false }); }); .FED@IBM
  • 28. Unit Tests const addIntegers = (a, b) => a + b; addIntegers(1.5, 'a'); // 1.5a .FED@IBM
  • 29. Unit Tests const addIntegers = (a, b) => { const { isInteger } = Number; invariant( isInteger(a) && isInteger(b), 'Expected integer arguments, instead got: [%s, %s]', a, b ); return a + b; } .FED@IBM
  • 30. Unit Tests const addIntegers = (a, b) => /* ... */ describe('add', () => { it('should warn if an argument is not an integer', () => { const a = 1; const b = 'a'; expect(add(a, b)).toThrow(); }); }); .FED@IBM
  • 35. Testing a Validator describe('Validator', () => { it('should validate a response from our API', () => { // ... }); }); .FED@IBM
  • 36. Testing getDuration describe('getDuration', () => { it('should get a duration value from an API response', () => { // ... }); }); .FED@IBM
  • 37. Integration Test import Validator from '../Validator'; import getDuration from '../getDuration'; describe('getResponseDuration', () => { it('should get a duration value from an API response', () => { const response = {}; const validated = Validator(response); expect(validated.passed).toBe(true); expect(validated.value).toBe(response.result.data); // ... }); }); .FED@IBM
  • 38. Integration Test describe('getResponseDuration', () => { it('should get a duration value from an API response', () => { const response = {}; const validated = Validator(response); expect(validated.passed).toBe(true); expect(validated.value).toBe(response.result.data); const durationCount = getDuration(validated.value); expect(durationCount).toBe(300); }); }); .FED@IBM
  • 40. E2E 
 Focus on real user scenarios, catching bugs before they reach the user. .FED@IBM
  • 41. E2E Scenario .FED@IBM Hits EnterLogin Form Clicks Form Enter Credentials
  • 43. Testing Pyramid .FED@IBM E2E Integration Unit Unit Testing Allows us to create a fast, reliable feedback loop that isolates errors. Requirements: Knowledge in areas such as dependency management, mocking, and hermetic testing.
  • 44. Testing Pyramid .FED@IBM E2E Integration Unit Integration Tests Allows us to verify the behavior of small groups of units
  • 45. Testing Pyramid .FED@IBM E2E Integration Unit End-to-End Tests Covers a small set of our product features to help catch bugs that may reach customers
  • 46. Take a Look Just Say No More to End-to-End Tests Covers the practicality of E2E tests, highlighting the advantages of favoring unit/integration tests over E2E. Move Fast and Don't Break Things Discusses the integration and role of testing in the context of Continuous Integration and Delivery Link Link
  • 47. Part 1 
 Writing a test .FED@IBM How to actually get started
  • 48. Setup 
 Test runners, assertions, and spies, oh my! .FED@IBM mocha chai karma expect expect.js jasmine sinon qunit selenium web driver ava jsdom
  • 50. Test Runner Allows us to write chunks of code to describe what should happen. Handles executing tests for us and returning the result. Assertion Library Spies Sometimes we need to check and verify that what we think will be called is actually called Enables us to state what we believe to be true, false, and a variety of other states. Testing
 Checklist .FED@IBM
  • 51. Test Runner Allows us to write chunks of code to describe what should happen. Handles executing tests for us and returning the result. Assertion Library Spies Sometimes we need to check and verify that what we think will be called is actually called Enables us to state what we believe to be true, false, and a variety of other states. Testing
 Checklist .FED@IBM DOM Mocking / Driver Allows us to verify that what we expect to happen in our product is actually happening
  • 52. Test Runner describe('Module', () => { it('should ...', () => { // ... }); }); .FED@IBM
  • 54. Take a Look Mocha Classic JavaScript test framework for JavaScript Jasmine DOM-less simple JavaScript Testing Framework https://www.npmjs.com/package/mocha https://www.npmjs.com/package/jasmine Karma Spectacular Test Runner for JavaScript https://www.npmjs.com/package/karma Ava Futuristic Test Runner for JavaScript https://www.npmjs.com/package/ava
  • 56. Assertions 
 Specify what you expect the outcome of a scenario to be. .FED@IBM
  • 57. Assertions describe('Module', () => { it('should ...', () => { const result = Module(); expect(result).toBe(2); }); }); .FED@IBM
  • 58. Assertions describe('Module', () => { it('should ...', () => { const result = Module(); expect(result).toEqual({ title: 'FEDucation', description: 'Coolest FED gathering in the world' }); }); }); .FED@IBM
  • 59. Assertions describe('Module', () => { it('should ...', () => { const result = Module(); expect(result).toEqual(['some', 'collection']); }); }); .FED@IBM
  • 60. Assertions describe('Module', () => { it('should ...', () => { const result = Module(); expect(result).toThrow(); }); }); .FED@IBM
  • 61. Assertions describe('Module', () => { it('should ...', () => { const result = Module(); expect(result).to.be.instanceOf(Error); }); }); .FED@IBM
  • 62. Assertions it('supports loading multiple keys in one call', async () => { var identityLoader = new DataLoader(keys => Promise.resolve(keys)); var promiseAll = identityLoader.loadMany([ 1, 2 ]); expect(promiseAll).to.be.instanceof(Promise); var values = await promiseAll; expect(values).to.deep.equal([ 1, 2 ]); var promiseEmpty = identityLoader.loadMany([]); expect(promiseEmpty).to.be.instanceof(Promise); var empty = await promiseEmpty; expect(empty).to.deep.equal([]); }); .FED@IBM
  • 63. Take a Look Expect Write better assertions Chai BDD/TDD assertion library for node.js and the browser https://www.npmjs.com/package/expect https://www.npmjs.com/package/chai Should Test framework agnostic BDD-style assertions https://www.npmjs.com/package/should Assert Native assertion library for Node.js
  • 64. Spies
  • 65. Spies 
 Stubs out any function and tracks calls to it and all arguments .FED@IBM
  • 66. Assertions const sum = (a, b) => a + b; describe('A spy', () => { it('should track that the spy was called', () => { spyOn(sum); sum(1, 2); expect(sum).toHaveBeenCalled(); expect(sum).toHaveBeenCalledWith(1, 2); }); }); .FED@IBM
  • 67. Assertions describe('Module', () => { it('should track that the spy was called', () => { spyOn(console, 'error'); const result = Module('invalid argument'); expect(console.error).toHaveBeenCalled(); expect(console.error) .toHaveBeenCalledWith('invalid argument'); }); }); .FED@IBM
  • 68. Isolation Achieves similar results to mocks, stubs, dummies, fakes, etc for accomplishing isolation Consistent Interface Partial Mocking You as the developer choose what portions of an interface you want to mock Spies follow the same interface as the functions that they're mocking Spies
 Highlights .FED@IBM
  • 69. Take a Look Jasmine DOM-less simple JavaScript Testing Framework Expect Write better assertions Sinon JavaScript test spies, stubs and mocks https://www.npmjs.com/package/sinon
  • 71. End-to-End Tests Prohibitively Expensive Loading up the browser, and performing a multitude of tests doesn't fit our ideal feedback loop for testing. Flakiness Race conditions, or other processes that may yield inconsistent results for a test due to using the DOM. Tooling In the past, we'd have to use complex tool chains like Selenium with Web Driver just to get E2E that don't actually help us, or the user.
  • 72. Take a Look jsdom A JavaScript implementation of the DOM and HTMl standards Karma Brings a productive testing environment to developers https://www.npmjs.com/package/jsdom https://www.npmjs.com/package/karma Selenium Web Driver Driving a browser natively as a user would http://docs.seleniumhq.org/projects/webdriver/
  • 73. DOM Mocking import jsdom from 'mocha-jsdom'; import { expect } from 'chai'; describe('mocha tests', function () { jsdom() it('has document', function () { var div = document.createElement('div') expect(div.nodeName).eql('DIV') }); }); .FED@IBM
  • 74. DOM Mocking it('should work for DOM events', function () { var div = document.createElement('div'); div.addEventListener('click', () => console.log('FEDs rule!')); spyOn(console, 'log'); div.click(); expect(console.log).toHaveBeenCalled(); expect(console.log).toHaveBeenCalledWith('FEDs rule!'); }); .FED@IBM
  • 75. DOM Mocking import jsdom from 'mocha-jsdom'; import { expect } from 'chai'; const markup = '<html>...</html>'; describe('mocha tests', function () { jsdom(markup) it('has document', function () { var app = document.querySelector('#app') expect(app.nodeName).eql('DIV') }); }); .FED@IBM
  • 76. Recap The Basics Overview of Unit, Integration, and End-to-End tests. The Tools Identify the necessary components that developers need for a robust testing framework. The Practice How do we go about structuring our tests, and begin writing tests using the techniques/testing frameworks that we've identified0
  • 77. Google 
 Focus on the user and all else will follow .FED@IBM
  • 78. Testing 
 Enables us to move fast and not break things .FED@IBM