“We want to deliver high quality
applications for our users while regularly
releasing new features”
Slide 3
Slide 4
Slide 5
00
Static analysis
Slide 6
Static analysis
Slide 7
“Static analysis
is the
analysis of
software
that is performed without
actually executing programs”
Slide 8
“Using Flow or
TypeScript
could have
prevented 15% of the public bugs for
public projects on GitHub”
http://
ttendency.cs.ucl.ac.uk
/projects/
type_study
/documents/
type_study.pdf
Slide 9
type
MyCustomButtonProps
= {
text
:
string
};
const
MyCustomButton
= ({
text
}:
MyCustomButtonProps
)
=>
(
<button>
{
text
}
</button>
);
const
ButtonContainer
= ()
=>
(
<
MyCustomButton
text
{
[
'I'
,
'like'
,
'turtles'
]
}
/>
);
Slide 10
Slide 11
“
You can have every single variable and
function
completely
typed and
linted
but
still
have none of your functions doing what they
should be
doing”
Slide 12
const
a
:
number
1
;
const
b
:
number
2
;
const
multiply
= (
a
:
number
,
b
:
number
):
number
=>
a
+
b
;
multiply
(
a
,
b
);
Slide 13
01
00
Static analysis
Unit testing
Slide 14
Unit testing
Slide 15
“A
unit test
is a way of testing a unit
the
smallest piece of code that can be logically
isolated in a system”
Slide 16
const
multiply
= (
a
:
number
,
b
:
number
):
number
=>
a
+
b
;
test
(
'Multiply should return the arguments multiplied'
, ()
=>
{
expect
(
multiply
(
4
,
3
)).
toBe
(
12
);
)};
Slide 17
expect(
received
).
toBe
(
expected
)
Expected value to be (using ===):
12
Received:
7
Slide 18
“
A snapshot test verifies that a piece of
functionality works the same as it did when
the snapshot was created
”
test.spec.js
✓
The Button component renders correctly (11ms)
Slide 21
FAIL
src
/
unit
test.spec.js
✕
The Button component renders correctly (15ms)
●
The Button component renders correctly
expect(
value
).
toMatchSnapshot
()
Received value
does not match
stored snapshot 1
.
Snapshot
Received
<button
className
="
btn
good"
+
className
="
btn
bad"
/>
Slide 22
“
You can have every single component and
function unit test passing but still have none
of your functions working together like they
should”
Slide 23
const
multiply
= (
a
:
number
,
b
:
number
):
number
=>
a
*
b
;
const
alertNumber
= (
value
:
number
):
void
=>
alert
(
value
);
const
ButtonWhichShouldAlertOnClick
= ()
=>
(
<button
onClick
{
()
=>
multiply
(
1
,
2
)
}
onMouseEnter
{
()
=>
alertNumber
(
multiply
(
1
,
2
))
}
Multiply
</button>
);
Slide 24
01
02
00
Static analysis
Unit testing
Integration testing
Slide 25
Integration testing
Slide 26
“Integration testing is the phase in
software
testing
in which individual software modules
are combined and tested as a group”
Slide 27
import
{
mount
}
from
'enzyme'
;
const
ButtonWhichShouldAlertOnClick
= ()
=>
(
<
button
onClick
{
()
=>
multiply
(
1
,
2
)
}
onMouseEnter
{
()
=>
alertNumber
(
multiply
(
1
,
2
))
}
Multiply
</button>
);
alertNumber
jest
.
fn
();
test
(
'The Button component should run a function on click'
, ()
=>
{
const
component
test.spec.js
✕
The Button component should run a function on click (22ms)
●
The Button component should run a function on click
expect(
jest.fn
()
).
toHaveBeenCalledTimes
(
1
)
Expected mock function to have been called
one time
, but it was called
zero times
.
Slide 29
“
You can have everything working together
completely as intended but still have an
empty screen for an
application”
Slide 30
const
multiply
= (
a
:
number
,
b
:
number
):
number
=>
a
*
b
;
const
alertNumber
= (
value
:
number
):
void
=>
alert
(
value
);
const
Button
= ()
=>
(
<button
onClick
01
02
03
00
Static analysis
Unit testing
Integration testing
User interface testing
Slide 32
User interface testing
Slide 33
“User
interface testing is the process of
testing a product's graphical user interface to
ensure it meets its
specifications”
Slide 34
t
ools
•
Protractor
•
Cypress
•
Puppeteer
•
Codecept
•
Navalia
•
Chromeless
•
Selenium
•
Nightmare
•
Nightwatch
•
Te s t C a f e
•
CasperJS
•
Te s t C a f e
Slide 35
import
{
Chrome
}
from
'
navalia
'
;
import
{
toMatchImageSnapshot
}
from
'jest
test.js
(
7.153s
)
✓
The routing input component should display as expected (3671ms)
Slide 38
Slide 39
FAIL
src
/components/routing
input/tests/
RoutingInput.ui
test.js
(
9.909s
)
✕
The routing input component should display as expected (9033ms)
●
The routing input component should display as expected
Expected image to match or be a close match to snapshot.
See diff for details:
/Users/p279825/Sites/ANWB/traffic/
src
/components/routing