A presentation at React Amsterdam Meetup in October 2017 in Amsterdam, Netherlands by Bart Waardenburg
The three layers of testing @bartwaardenburg
“We want to deliver high quality applications for our users while regularly releasing new features”
00 Static analysis
Static analysis
“Static analysis is the analysis of software that is performed without actually executing programs”
“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
{ [ 'I' , 'like' , 'turtles' ] } /> );
“ 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”
2 ; const multiply = ( a : number , b : number ): number => a + b ; multiply ( a , b );
01 00 Static analysis Unit testing
Unit testing
the smallest piece of code that can be logically isolated in a system”
const multiply = ( a : number , b : number ): number => a + b ; test ( 'Multiply should return the arguments multiplied' , () => { expect ( multiply ( 4 , 3 )). toBe ( 12 ); )};
expect( received ). toBe ( expected ) Expected value to be (using ===): 12 Received: 7
“ A snapshot test verifies that a piece of functionality works the same as it did when the snapshot was created ”
”good" /> ). toJSON (); expect ( component ). toMatchSnapshot (); });
test.spec.js ✓ The Button component renders correctly (11ms)
Snapshot
bad" />
“ You can have every single component and function unit test passing but still have none of your functions working together like they should”
{ () => alertNumber ( multiply ( 1 , 2 )) }
Multiply </button> );
01 02 00 Static analysis Unit testing Integration testing
Integration testing
“Integration testing is the phase in software testing in which individual software modules are combined and tested as a group”
"test" /> ); component . find ( 'button' ). simulate ( 'click' ); expect ( alertNumber ). toHaveBeenCalledTimes ( 1 ); });
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 .
“ You can have everything working together completely as intended but still have an empty screen for an application”
'display: none' ;
01 02 03 00 Static analysis Unit testing Integration testing User interface testing
User interface testing
“User interface testing is the process of testing a product's graphical user interface to ensure it meets its specifications”
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
input' ); await chrome . done (); expect ( screenshot ). toMatchImageSnapshot (); });
test.js ( 7.153s ) ✓ The routing input component should display as expected (3671ms)
diff.png
new Buffer ( screenshot , 'base64' ); expect ( file ). toMatchImageSnapshot (); await chromeless . end ();
here’, }, });
“With chromeless you can run hundreds of browsers in parallel”
“You can easily execute > 100.000 tests for free in the free tier ”
t hanks & happy testing @bartwaardenburg
View React and the Three Layers of Testing on Notist.
Dismiss
I will discuss our Three Layers of Testing (tm) we use when developing new features for one of our high traffic web applications at the ANWB.