Testing

What is testing? 

something that throws an error when something is wrong, tells us what went wrong, what was expected, what we got, and where.

Some people refer to this as TDD, but TDD (Test-Driven Development or Test-Driven Design) is a specific methodology of Testing, where the tests are written first and drive the design and implementation of the product.

Why Bother with Testing?

Your tests are your first and best line of defense against software defects.

  • You’re more productive because you don’t have to spend the time manually testing the code yourself.
     
  • You can make changes to the code without worrying if something is broken (as long as the tests pass).
     
  • Tests provide documentation for what your code is actually meant to do.

Red Green Refactor 🚦

There are two goals of red green refactor.

  • First, the tests should break when something goes wrong. Passing tests aren’t good enough if they don’t fail when the wrong things happen.
     
  • Second, the tests should fail until your code does what you expect. This allows you to immediately know if you’ve written your code correctly.

Title Text

Write your code in the following order:

 

  1. Write your test, it should fail.
     

  2. Write only enough code to make your test pass (and not a single keystroke more!)
     

  3. Refactor any existing code to make it more readable, performant, etc., but do not change or add any functionality. Your tests should still pass!

Title Text

Static Testing

it is testing the code without executing it.
Manually checking the code, requirement documents, and design documents to find errors. Hence, the name "static".

Prettier, ESLint

Dynamic Testing

  • It checks for functional behavior of software system , memory/cpu usage and overall performance of the system.
     
  • Dynamic testing executes the software and validates the output with the expected outcome.
     
  • Dynamic testing is performed at all levels of testing

Unit Testing

A unit test runs some code over a segment of your program checking the input and output.

These tests allow developers to check individual areas of a program to see where(and why) errors occur.

mocha, jest

Integration tests

Integration tests are used to test multiple, bigger units (components) in interaction, and can sometimes even span multiple systems.

The purpose of integration tests is to find bugs in the connections and dependencies between various components, such as: Passing invalid or incorrectly ordered arguments.

E2E

end to end testing, where we test the whole application together, and test it as a user would — essentially automating whatever the user does.

JavaScript
Tests

 

jest

Jest is a fast JavaScript testing utility by Facebook that enables you to get started with testing your JavaScript code with zero configuration.

Jest acts as a test runner, assertion library, and mocking library.

Enzyme

Enzyme is a JavaScript Testing utility for React that makes it easier to assert, manipulate, and traverse your React Components’ output.

npx create-react-app testing
cd testing
npm test
npm i enzyme enzyme-adapter-react-16 

Resources

  • https://airbnb.io/enzyme/
  • https://jestjs.io/en/
  • https://testdriven.io/tdd-with-react-jest-and-enzyme-part-one
  • https://medium.com/@leonardobrunolima/react-tips-testing-react-component-with-jest-enzyme-basics-38a15d5dd72a
  • https://scotch.io/tutorials/testing-react-components-with-enzyme-and-jest
  • https://medium.com/codeclan/testing-react-with-jest-and-enzyme-20505fec4675
  • https://slides.com/kentcdodds/testing-principles#/

LevelUp - Testing

By Habiba Gadalla

LevelUp - Testing

intro to testing

  • 44