> A QA engineer walks into a bar. Orders a beer. Orders 0 beers. Orders 99999999999 beers. Orders a lizard. Orders -1 beers. Orders a ueicbksjdhd. > >First real customer walks in and asks where the bathroom is. The bar bursts into flames, killing everyone. --- # QA role FAC alumni mentor: Katia Company: @StoryShareTech --- # Responsibilities: 1. Monitor codecov and make sure test coverage is kept up 2. Understand how to test pure functions, database queries, routes, DOM 3. Understand how and when to use mocks 4. Set up separate test database and destroy / build scripts 5. Insist on clean and legible code --- # Some words and letters - Unit - Integration - Regression - E2E - UAT, manual, automated - Black box, white box --- ## JS testing frameworks - Jest (pre-built in CRA) - Mocha - Jasmin - Tape - AVA --- ## JS helper libraries - React Testing Library - Enzyme (was 😎 *_before_* hooks) - React Test Utils --- ## Advantages of Jest - One-Stop Shop - created and documented by Facebook - built-in mocks and spies (no need for Sinon) - snapshots - preconfigured with CRA --- ## Jest testing pure functions ```jsx= const { sum } = require('./math'); test('Adding 1 + 1 equals 2', () => { expect(sum(1, 1)).toBe(2); }); ``` --- ## Mocks Mocking - creating a completely fake object ```jsx= test("mock implementation", () => { const mock = jest.fn(() => "bar"); expect(mock("foo")).toBe("bar"); expect(mock).toHaveBeenCalledWith("foo"); }); ``` --- ## Snapshot tests ```jsx= import React from 'react'; import renderer from 'react-test-renderer'; import { Award } from './Award'; describe('testing the Award component', () => { it('renders correct ui elements', () => { const awardProps = { color: 'yellow', }; const component = renderer.create( <Award { ...awardProps } /> ); const tree = component.toJSON(); expect(tree).toMatchSnapshot(); }); }); ``` --- ## Snapshots. ```jsx // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`Award component renders correct ui 1`] = ` <button className="button__award--trimmed" onClick={[Function]} > <i aria-hidden="true" className="icon__award--yellow" onClick={[Function]} /> </button> `; ``` --- ## [Codecov](https://codecov.io/) and edge cases | Measure | Advantages | Disadvantages | | ---- | ----- | -------- | | Codecov | Looks good on GitHub, helps the team to understand the functionality | May miss out important edge cases, time consuming | | Edge Cases | You only test what needs testing | Hard to measure | --- codecov.io visualised test coverage ![](https://i.imgur.com/M4VvmDk.png) --- ## DB or not DB > ### Good - Postgres knowledge boosts employability - You had to learn some SQL - SQL is fun - SQL can calculate - There is MongoDB > ### Bad - Creating and testing a database is hard --- ## Testing a test database 1. Make sure you are testing a test database. Create it, for example. 2. Connect to it from your test suite 3. Disconnect from your db ```js= const dbconnection = require('../database/db_connection'); afterAll(() => { dbconnection.$pool.end(); }); ``` --- ## Making sure your tests use the _test_ db > ```jsx= describe('Check the environment is test', () => { test('Should fail if not test env', () => { expect(process.env.NODE_ENV).toEqual('test'); }); }); ``` --- ## Some DB tests ```jsx= describe('Test user 1 payslip data', () => { test('Test that payslip exists on entry', () => { let date1 = '2018-06-01'; let date2 = new Date('2018-06-15'); return insertPayslip(1, date1, date2, 100).then(res => { expect(res[0].start).toBe('2018-06-01'); }); }); test('Test that total paid hours include breaks', () => { return getHoursWorked(1, '2018-6-30', '2018-7-5').then(res => { expect(res[0].hours).toBe(6); }); }); }); ```
{"metaMigratedAt":"2023-06-14T15:46:50.906Z","metaMigratedFrom":"YAML","title":"QA role","breaks":true,"slideOptions":"{\"transition\":\"slide\"}","contributors":"[{\"id\":\"0f7a35ec-f2b1-4089-943c-17d8603eb062\",\"add\":5335,\"del\":1416}]"}
    246 views