Tests e2e
Nightmare/nightwatch.js
e2e ?
e2e vs unit tests
- Same goal
- Completely different methodology
- Both have benefits and limitations (e2e are generally slow, brittle, more complicated to write/maintain)
e2e vs unit tests
https://martinfowler.com/bliki/TestPyramid.html
Test repartition
- 100% unit test coverage as a goalĀ
- Only critical business parts should be (~20% ?)
- Agile / incremental dev methodologies make test harder to maintain
What about QA ?
https://www.joelonsoftware.com/2000/04/30/top-five-wrong-reasons-you-dont-have-testers/
- QA can help define/write e2e tests
- Time saved by automated test can be used for "exploratory testing"
When to run tests ?
- Prod-like environment
- After pull request ?
- Do what I say, not what I do
Why Nightmare
- Only JS (electron based), easy to configure
- Good docs, wide use on Github
- Easy to use with mocha
Why not Nightwatch
- Needs Java installed & selenium
- Few differences, no advantages in a demo
Other choices
- Protractor (e2e testing for angular apps)
- Nightwatch.js (based on Selenium)
- Codecept.js ("meta language for js e2e testing)
http://codecept.io/nightmare/
How to install it ?
- npm i nightmare
Api
- .goto(url)
- .wait(1000)
- .click(selectorCSS)
- .type('input', 'some text')
- .back()
- .format()
- .refresh()
Api
var Nightmare = require('nightmare');
var nightmare = Nightmare({ show: true });
nightmare
.goto('https://sfeir.com')
// ...
.end()
Demo
Conclusion
- Hardest part is defining test + CSS selectors
- Remember testing pyramid/20% rule
- One browser is enough for automated testing IMO
Thanks
Any questions or feedback about e2e tests ?
Tests e2e avec nightmare/nightwatch.js
By Alexandre BARBIER
Tests e2e avec nightmare/nightwatch.js
- 469