testing
#2 Pencils Not Required
✏️
questions: @zachfedor
who tests their code?
🙌
test
noun:
a procedure intended to establish the quality, performance, or reliability of something, especially before it is taken into widespread use.
who tests their code?
🙌
objective:
make testing approachable
why test?
- make sure users can do what they need to do
why automate your tests?
scenario #1
-
build a thing. be happy.
-
see if it worked.
-
it didn't.
-
be confused...
this is repetitive and time consuming.
tests handle the repetition for you.
📝
why automate your tests?
scenario #2
-
get a new project. be happy.
-
build all the things.
-
look back at your work.
-
be confused...
code is complex.
tests help document it.
⚠️
why automate your tests?
scenario #3
- have a working site. client is happy.
- client wants a new thing. make a change.
- new stuff works. old stuff doesn't.
- be confused...
code grows over time.
tests help prevent growing pains.
🎛️
why automate your tests?
scenario #4
- make a new thing. it works.
- give it to the client. they're happy.
- users still find a way to break it.
- be confused...
even simple features have edge cases.
tests help cover all your bases.
🏗️
why automate your tests?
scenario #5
- get asked to make a new thing
- ...
- ...
- be confused...
manual tests make you build first.
tests help you design first.
Types Of Tests
Unit: make sure a small piece of code does it's one job well
Integration: make sure two pieces of code work together properly
Acceptance: make sure the user can do a task from start to finish
Examples
Unit
add(2, 3)
user.isLoggedIn()
$input.hasClass("error")
👌
👌
👌
5
true
false
Examples
Integration
form.submit()
$conn->query($sql)
<a onclick="myFunc(e)">
👌
👌
👌
http.response
true
MouseEvent
Examples
Acceptance
👌
👌
👌
A user can create an account
A user can filter a list of products
A user can submit their order
Unit
Integration
Acceptance
Touchpoints
Variables
Code
Resources
Time
Complexity
#
okay.
so what is a test?
// Every Unit Test Should...
Describe the thing you're testing {
say(what it should do);
define expected = result;
// by knowing what it should do
define actual = result;
// by doing the thing
compare(actual, expected);
}
// add.js
function add (x, y) {
return x + y;
}
// add.test.js
describe('add()', () => {
it('should take two numbers and return their sum', () => {
const actual = add(2, 3);
const expected = 5;
expect(actual).toBe(5);
);
});
test frameworks
- jest
- ava
- mocha
- jasmine
- qunit
- cucumber
- tape
assertion libraries
- assert.js
- expect.js
- should.js
- chai
test utilities
- sinon
- enzyme
- jsdom
- phantom.js
- selenium
- nock
- supertest
tips and advice
- every test helps
- the law of diminishing returns
- replace console.logs with a test
- if tests are hard to write, it could mean:
- your code is hard to test
- your goal isn't clearly defined
- you don't fully understand your tools
questions
for new testers
- how many of you are thinking about starting to test your code now?
- what might be preventing you from starting?
questions
for old testers
- what other tips can you offer those who are just starting?
- what still trips you up about testing?
thanks!
Testing: #2 Pencils Not Required
By zach fedor
Testing: #2 Pencils Not Required
I'll explain the benefits of automated testing for your front-end code, cover some best practices and helpful tips, and show a demo or three to get you started.
- 1,426