TESTING SOFTWARE TESTING "Software testing is an investigation - - PowerPoint PPT Presentation

testing software testing
SMART_READER_LITE
LIVE PREVIEW

TESTING SOFTWARE TESTING "Software testing is an investigation - - PowerPoint PPT Presentation

CS 498RK SPRING 2020 TESTING SOFTWARE TESTING "Software testing is an investigation conducted to provide stakeholders with information about the quality of the software product or service under test." i . e . checkin g tha t ou r cod e


slide-1
SLIDE 1

SPRING 2020 CS 498RK

TESTING

slide-2
SLIDE 2

SOFTWARE TESTING

"Software testing is an investigation conducted to provide stakeholders with information about the quality of the software product or service under test."

https://en.wikipedia.org/wiki/Software_testing

i.e. checking that our code meets some expectations

slide-3
SLIDE 3

TESTING LEVELS

Unit Tests: For individual units like functions, classes, etc. Integration Tests: Across several units to ensure they "play well" together. End-to-end Tests: Using the complete product to perform certain scenarios.

slide-4
SLIDE 4

UNIT TESTS

Cover small, pure units of an app - utils, services and helpers Provide inputs and expect

  • utputs for general, edge and

error cases Check code coverage

slide-5
SLIDE 5

INTEGRATION TESTS

Cover cross-module processes - across several classes, FE-BE interactions Use spies to check side effects Component snapshot tests

slide-6
SLIDE 6

END-TO-END TESTS

AKA e2e or functional tests Browser automation Simulate clicks, scrolls, typing Treat the app as a black box Ensure correct end user experience Visual Regression

slide-7
SLIDE 7

RUNNING TESTS

Running in the browser — Create an HTML page with the test libraries and files Using a "headless" browser — Launch browsers without actually rendering them on the screen Executing in Node.js — import test files and dependencies and simulate the browser behavior (jsdom)

slide-8
SLIDE 8

TEST LAUNCHERS

Launch test suites using a configuration file

module.exports = function(config) { config.set({ basePath: '../..', frameworks: ['jasmine'], autoWatch: true, browsers: ['Firefox', 'Chrome'], files: ['test/unit/*.spec.js'], //... }) }

slide-9
SLIDE 9

STRUCTURE

describe('calculator', () => { describe('add', () => { test('should add 2 numbers', () => { ... }) describe('divide', () => { test('should throw an error when the divisor is zero', () => { ... }) ... })

Usually follow a BDD structure (Behavior-Driven Development)

slide-10
SLIDE 10

ASSERTIONS

expect(bestLaCroixFlavor()).toBe('grapefruit') expect(0.2 + 0.1).toBeCloseTo(0.3, 5); expect(ouncesPerCan()).toBeGreaterThan(10); expect(() => { }).toBeInstanceOf(Function); expect(getAllFlavors()).toContain('lime');

Used to make sure tested values contain the expected value

slide-11
SLIDE 11

SPIES

describe('drink functions', () => { test('drinkAll drinks something lemon-flavoured', () => { const drink = jest.fn(); drinkAll(drink, 'lemon'); expect(drink).toHaveBeenCalled(); }); test('drinkEach drinks each drink', () => { const drink = jest.fn(); drinkEach(drink, ['lemon', 'octopus']); expect(drink).toHaveBeenCalledTimes(2); }); });

Provide extra information about functions and side-effects

slide-12
SLIDE 12

STUBS

Replace selected functions of existing modules to ensure consistent test behavior

// Jest user.isValid = jest.fn(() => true) // Sinon sinon.stub(user, 'isValid').returns(true) // Jasmine spyOn(user, 'isValid').andReturns(true)

slide-13
SLIDE 13

MOCKS

describe('getComments', () => { test('fetches comments from the server', done => { const server = sinon.createFakeServer() server.respondWith("GET", "/some/article/comments.json", [200, { "Content-Type": "application/json" }, '[{ "id": 12, "comment": "Hey there" }]']); getComments("/some/article").then((res) => { expect(res.toJSON()).toBe([ { id: 1, name: 'Gwen' }, { id: 2, name: 'John' } ]); expect(server.requests.length).toBeGreaterThan(1); }) server.respond(); server.restore(); }); });

Fake certain modules and behaviors to test a different part of a process

slide-14
SLIDE 14

SNAPSHOT TESTING

Allows you to compare a data structure to what it was in older releases. No rendering required. Save internal data in a separate file and compare when a test is executed.

slide-15
SLIDE 15

SNAPSHOT TESTING

import React from 'react'; import Link from '../Link.react'; import renderer from 'react-test-renderer'; it('renders correctly', () => { const tree = renderer .create(<Link page="http://www.facebook.com">Facebook</Link>) .toJSON(); expect(tree).toMatchSnapshot(); });

exports[`renders correctly 1`] = ` <a className="normal" href="http://www.facebook.com"

  • nMouseEnter={[Function]}
  • nMouseLeave={[Function]}

> Facebook </a> `;

slide-16
SLIDE 16

demo

https://gitlab.com/uiuc-web- programming/testing-demo

slide-17
SLIDE 17

"Program testing can be used to show the presence of bugs, but never to show their absence!"

— Edsger W. Dijkstra

slide-18
SLIDE 18

RESOURCES

Jest - https://jestjs.io/ Karma - https://karma-runner.github.io/ Jasmine - https://jasmine.github.io/ Sinon - https://sinonjs.org/ Istanbul - https://istanbul.js.org/ Nightwatch - https://nightwatchjs.org/ PhantomJS - https://phantomjs.org/

slide-19
SLIDE 19

MORE RESOURCES

An Overview of JavaScript Testing in 2020 https://medium.com/welldone-software/an-

  • verview-of-javascript-testing-7ce7298b9870


Snapshot Testing with Jest https://jestjs.io/docs/en/snapshot-testing