Presentation for session on #Tarabica 17 conference
JavaScript code is code - and as more and more code is done with it, we need to test it to ensure that the code is functional. This presentation will provide an overview of the current state of the art of testing JavaScript, focusing on the available toolchain.
Tools that will be used during the presentation include Jasmine, Karma, Istanbul, Stryker.
Code is available at https://github.com/sweko/testing-javascript
5. #tarabica17
>whoami
Head of Development in Sourcico Macedonia
Coding professionally since last century
I love programming
I love programmers
Rabid about code quality
I hate JavaScript, but I love web development
6. #tarabica17
Agenda
• Why do we need to test software?
• How do we test software?
• Why do we need unit tests?
• How to unit test javascript?
• How to test the unit tests?
• How to test everything else?
8. #tarabica17
Why do we need to test?
• Software has bugs
• Users and clients have bugs too
• The problem space is extremely complex
• Software is never done done
9. #tarabica17
How do we test?
• Manual testing
• Automated testing – we're developers, after all
• Unit Tests
• Integration Tests
• Load Tests
• CI/CD Pipeline integration
11. #tarabica17
Why unit test software?
• White –box testing
• People who know the unit best
• Promotes flexible design
• Fearless coding
• Free regression coverage
12. #tarabica17
Unit testing myths
• Testers test – developers develop
• It's dull to write tests – we have interns for that
• We're on a tight schedule – no time for testing
• Of course we'll write tests. Only later.
• The tests will fail if I change the code
13. #tarabica17
Unit testing myths
• Unit testing is weak at finding problems that haven't
been considered.
• It takes too much time and effort to think of all
possible tests and implement them.
• Our methods are not easily testable.
• It's not feasible for large or existing projects
14. #tarabica17
Unit testing myths
• It saves money
• It reduces the number of bugs
• It brings a higher quality
• It improves performance
• Code Coverage is a great metric
19. #tarabica17
Testing the unit tests
• Code coverage is not magic
• Covered code is covered code – not correct code
• Mutations on the code under tests
• Running of a full test suite
• Reach / Infect / Propagate - RIP
22. #tarabica17
Is unit testing enough?
• What happers if we only use unit tests
• Bigger picture tests
• Testing UI behaviour
• Testing browser behaviour
• Testing accross devices