Realdolmen Education

Details

JavaScript Unit Testing

Deze cursus is momenteel niet ingepland op de open kalender, maar kan op aanvraag georganiseerd worden.

Cursus aanvragen

Aantal dagen

3 day(s)

Audience

JavaScript developers.

Prerequisites

Good understanding of JavaScript programming basics.

Objectives

Learn how to write unit tests for JavaScript applications in the browser and server-side.

Methods

Classroom training with hands-on exercises.

Description

Although JavaScript is not a new language, it's ecosystem has been in constant change over the last years. Recent evolutions include both more server-side (e.g. Node.js) and more client-side (e.g. browsers) focus. Other changes are the language evolution itself (ES2015, ES2016, …) and the use of “bundler” tools (e.g. Webpack, Browserify, …). This means that in many cases, JavaScript takes over more of the roles of the classical platforms like Java, and C#. One of these is the aspect of “unit testing”; the more business logic moves to the JavaScript domain, the more important the aspect of unit testing there becomes.

This course, intended for JavaScript developers, handles all of these aspects using a structured approach. Starting with the general concepts of unit testing, we gradually progress to practical implementation and design using popular frameworks like Mocha and Chai. Moving on to more advanced topics such as “mocking” and “stubbing”, we explore how to work with Sinon. Throughout the course we also take the time to focus on the unique challenges of running unit tests in the browser, where we have to tackle problems like “bundling” using Browserify and Webpack. These tasks can be automated using Karma, which we cover as the last topic of the course. For each topic we’ll have the chance to gain some practical experience with worked out hands-on exercises.

Contents

  • 1. JavaScript Unit Testing
    • 1.1. Course Objectives
    • 1.2. Agenda
  • 2. Introduction
    • 2.1. Rationale
    • 2.2. Node.js
    • 2.3. Testing Frameworks
    • 2.4. Helper Frameworks and Libraries
    • 2.5. Continuous Integration
    • 2.6. Continuous Integration Showcase: Jenkins
  • 3. Software Testing Concepts
    • 3.1. Software Testing
    • 3.2. Testing Aspects
    • 3.3. Testing Approaches
    • 3.4. Manual vs Automated Testing
    • 3.5. Static vs Dynamic Testing
    • 3.6. Black-box vs White-box Testing
    • 3.7. Iterative vs Sequential Testing
    • 3.8. High-level vs Low-level
    • 3.9. Unit Testing
  • 4. Mocha with Chai
    • 4.1. What is Mocha?
    • 4.2. Installing Mocha
    • 4.3. Getting Started
    • 4.4. Tool Support
    • 4.5. Creating Tests
    • 4.6. Test Suites
    • 4.7. Assertion Libraries
    • 4.8. Chai
    • 4.9. Chai Assert Style
    • 4.10. Chai 'Should' and 'Expect' Style
    • 4.11. Chai Should and Expect Style
    • 4.12. Asynchronous Code
    • 4.13. Chai as Promised
    • 4.14. Hooks
    • 4.15. Test Context
    • 4.16. Test Retries and Timeouts
    • 4.17. Test Durations
    • 4.18. Excluding and Including Tests
    • 4.19. Generating Tests
    • 4.20. Browser Support
    • 4.21. Browser Tests Without Bundler
    • 4.22. Browser Module Loading
    • 4.23. Browser Tests With Bundler
    • 4.24. Interfaces
    • 4.25. Reporters
    • 4.26. Command-line Interface
    • 4.27. Mocha.opts
  • 5. Mocking Concepts
    • 5.1. Collaborators
    • 5.2. System Under Test
    • 5.3. Mocking
    • 5.4. Terminology: Mock, Stub, Spy, Fake, Double
    • 5.5. Mocks Aren't Stubs
    • 5.6. State Verification
    • 5.7. Behaviour Verification
  • 6. Sinon.js
    • 6.1. What is Sinon.js?
    • 6.2. Enabling Sinon.js
    • 6.3. Spies
    • 6.4. Creating Spies
    • 6.5. Spy Interface
    • 6.6. Sinon Assertions
    • 6.7. Sinon Matchers
    • 6.8. Stubs
    • 6.9. Creating Stubs
    • 6.10. Stub Interface
    • 6.11. Stubbing with Promises
    • 6.12. Examples Using Stubs
    • 6.13. Mocks
    • 6.14. Creating Mocks
    • 6.15. Mock Expectations Interface
    • 6.16. Examples Using Mocks
    • 6.17. Sinon in the Browser
    • 6.18. Faking XMLHttpRequest
    • 6.19. Fake Server
    • 6.20. Faking Timers
    • 6.21. Sandboxes
  • 7. Karma
    • 7.1. What is Karma?
    • 7.2. Karma Features
    • 7.3. Working Principle
    • 7.4. Installing Karma
    • 7.5. Adding Browser Support
    • 7.6. Minimal Karma Configuration
    • 7.7. Adding Tests
    • 7.8. Launching Karma
    • 7.9. Advanced Karma Configuration
    • 7.10. Karma File Configuration
    • 7.11. Karma Reporters
    • 7.12. Karma Logging
    • 7.13. PhantomJS Launcher
    • 7.14. Customizing Launchers
    • 7.15. Example: Testing With DOM API
    • 7.16. Preprocessors
    • 7.17. Example: Webpack bundling using Preprocessor