Testing

Unit testing

Why use unit testing

  • To make your code predictable
  • Minimise errors for the user
  • To make code more efficient
  • Other developers should be able to understand the application from reading tests

What to test

  • All the functions in your code
  • All the parameters of your function

 

Keep in mind that your functions are small in order to increase the testability.

How to test

  • All the functions in your code
  • All the parameters of your function

Tools

  • JavaScript 
    • Jasmine (lib)
    • Mocha (lib)
    • Chai (lib)
    • Jest (lib)
    • JSUnit (lib)
    • Instanbul (coverage)
    • Sinon.JS (stub & mocking)
  • Java 
    • JTest
    • JUnit

 

  • PHP
    • PHPUnit

Maintenance

It is super important to maintain your tests according to your code. Otherwise, some tests will fail and others become un-necessary.

Coverage

With a tool like "Instanbul" we can keep track of the test coverage of our code.

 

With the coverage we can see which part of our code is tested and what not.

Test Driven Development

With TDD we first write our test and after it the code in order to let the test pass.

 

TDD we ensure that we only write code we need and write code that is predictable.

Integration testing

or End-to-End testing

Why use integration testing

  • What happens when our API or external service is down.
  • Does everything work except that part of the application
  • Does the user get a proper error message

What to test

The integration between the Front-end and Back-end services.

How to test

  • Block temporary the API call's to the API
  • Try to login with bad credentials
  • Send wrong data to an API

Tools

  • Cucumber
  • Cypress
  • Protractor
  • Selenium WebDriverIO
  • TestCafé

Browser testing

Why use browser testing

  • Does the application works as expected
  • We want to make sure that all our visitors have a great user experience.

What to test

  • Is the application responsive.
  • Is the positioning of the layout equal in all browsers
  • Is the application loading time not slow
  • Is the memory consumption acceptable
  • etc...

How to test manually

Just test the application across browsers, platforms and mobile devices.

How to test automatically

With different tools we can automate some part of the behavioral things of the application.

 

Testing styling in different browsers automatically needs some more effort. We can use tools that make screenshots and compare that to a base image of every component or layout.

(Normal) browsers

A browser with a visual user interface that runs a computer, tablet & smartphone.

  • Chrome
  • Firefox
  • Safari
  • Opera
  • Edge
  • Internet Explorer
  • Chromium (source for Chrome)
  • Chrome Canary (Beta of Chrome)
  • Firefox Developer Edition
  • Blisk

Selenium can automate the normal browser testing

Headless browsers

A browser without any visual user interface that runs on the terminal.

 

  • Puppeteer (headless chrome)
  • SlimerJS (headless firefox)
  • PhantomJS (headless webkit browsers)
  • Selenium (Can run different headless browsers)

Tools for manual testing

  • (Normal) Browsers
  • Devtools
  • Real devices
  • Debugger

Tools for automatic testing

  • CasperJS (test library for PhantomJS & SlimerJS)
  • Nightmare (PhantomJS automation library)
  • Nightwatch (automation testing framework for Selenium
  • Cucumer (BDD tool to automate browser testing)

Regression testing

What is regression testing

Performing a test after making changes, we can test if the written tests are still passing.

Why and how to do regression testing

If there are (automatic) tests you perform, you can perform this every time you have created a new feature or functionality.

 

If the features or functionality breaks the tests, it can mean that the tests needs to be changed or the feature has to change.

Performance testing

Why do performance testing

A performance test should be done to ensure that the performance of the application is good in different circumstances.

What to test for performance

  • Bottlenecks in browser or server
  • The CPU/memory usage for a device or server during the usage of the application
  • Load/stress test for testing the server architecture
  • Browser loading performance

How to run a manual performance test

  • Performance test in Browser Devtools tab
  • Load performance in the browser via Google PageSpeed, WebPageTest.org

How to run a automatic performance test

  • Sitespeed.io (npm package that you can intergrate with any taskrunner)
  • Apache JMeter (opensource performance and loadtest tool for Java)
  • Lighthouse (npm package, cli tool and included in Chrome Devtool)

Usability testing

Why use usability testing

To make sure that the user interface is in line with how the user would use the interface in order to perform certain tasks.

What to test

The user-interface.

How to test

Usability tests will most of the time be done by the user them self.

 

Some companies will invite a few of their users and ask them to perform different tasks.

 

The user will perform this on a computer that has an eye tracking camera to track eye movement.

 

Via this way the company can collect data and change their user-interface based on the actions of the user.

Linting

Why use linting​

To automatically check the code on code style and best practices.

What to lint

For most of the programming languages there are linting tools.

Tools

  • ESLint (JavaScript)
  • StyleLint (CSS, SCSS, Sass)
  • HTMLLint (HTML)
  • PHPLint (PHP)
  • PyCodestyle (Python)
  • Checkstyle (Java)
  • Rubocop (Ruby)
  • Golint (Go Lang)

Testing

By CodePamoja

Testing

  • 43