slides.com/brandonb927/testing-web-applications-with-cypress
QA Developer @ Dyspatch
@brandonb927
brandonb.ca
A cloud-based communications management platform that helps Enterprise organizations centralize their email creation, approval, and publishing processes.
startupslam.io
battlesnake.io
It's fun!
It will save you time
It's good practice
Reduces side effects
Mitigate regressions
Codebases are built on unit tests, supplemented by integration tests, topped with end-to-end tests.
Unit tests are supposedly where you spend your time in testing code. Integration tests are where you spend slightly less time.
Cap it off with a small set of "happy path" end-to-end tests.
Mike Cohn, circa 2004
"The Testing Trophy" 🏆
A general guide for the **return on investment** 🤑 of the different forms of testing with regards to testing JavaScript applications.
- End to end w/ @Cypress_io ⚫️
- Integration & Unit w/ @fbjest 🃏
- Static w/ @flowtype 𝙁 and @geteslint ⬣
Kent C. Dodds
@kentcdodds
PayPal Eng & TC39 Member
$ npm install -d jest
$ npm test
const foo = require('./foo')
describe('foo', () => {
it('adds bar', () => {
expect(foo('bar')).toBe('foobar')
})
})
1. Install unit-testing framework
3. Run the tests
2. Write a unit test
What is it?
"End to end" (shortened to E2E) is methodology used to test whether the flow of an application is performing as designed from start to finish. E2E ensures the happy path is maintained for customers.
Unit tests and integration tests only take a small piece of the application and assess that piece in isolation.
Even if these pieces work well by themselves, you don’t necessarily know if they’ll work together as a whole. Having a suite of end-to-end tests on top of unit and integration tests allows us to test our entire application.
OG Browser Automation Tool
Pictured: An operator running the Selenium test suite for their app
Built for web developers by web developers
Automated testing INSIDE a browser
Incredible developer experience
Amazing & well-written docs
Easily write "happy path" tests for workflows that could go untested/unnoticed in production
Focuses on doing E2E testing REALLY well
Works on any front-end framework or website
🚫 No Selenium ⇒ ✅ Electron, Chromium (more browsers eventually)
Tests are written in JavaScript, run in isolation (via js function closures)
Utilizes Mocha, Chai, and Sinon under the hood for BDD syntax, test assertions, and function stubs/spies
Debugging tests is a breeze
DevTools access in the test runner UI, like a browser
Readable text output and optional JUnit test reports in CI/headless mode
Docker images for CI/headless mode
Cypress is most often compared to Selenium; however Cypress is both fundamentally and architecturally different. Cypress is not constrained by the same restrictions as Selenium.
This enables you to write faster, easier and more reliable tests.
Selenium
Cypress
$ npm install -d cypress
λ npm install -d cypress
> cypress@2.1.0 postinstall /Users/brandon/p/node_modules/cypress
> node index.js --exec install
Installing Cypress (version: 2.1.0)
✔ Downloaded Cypress
✔ Unzipped Cypress
✔ Finished Installation /Users/brandon/p/node_modules/cypress/dist/Cypress.app
You can now open Cypress by running: node_modules/.bin/cypress open
https://on.cypress.io/installing-cypress
Installs cypress into your current project/folder
$ ./node_modules/.bin/cypress open
Opens the Cypress test runner UI
describe('My First Test', () => {
it('Gets, types, and asserts', () => {
cy.visit('https://example.cypress.io')
cy.contains('type').click()
// Should be on a new URL which includes '/commands/actions'
cy.url().should('include', '/commands/actions')
// Get an input, type into it, and verify that the value has been updated
cy.get('.action-email')
.type('fake@email.com')
.should('have.value', 'fake@email.com')
})
})
$ touch cypress/integration/home_page_spec.js
Testing the flow of navigation & form input value
Creates the empty spec file
@brandonb927
brandonb.ca
slides.com/brandonb927/testing-web-applications-with-cypress