Git Product home page Git Product logo

ibabalola / test-driven-development Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 835 KB

TDD is one of the most hotly discussed subjects in the software development world. Even the most carefully constructed applications grow to the point where debugging and ensuring quality becomes difficult. Test-driven development (TDD) helps with this tremendously by ensuring that all parts of your application are covered by tests. In this course, Shaun Wassell explores the foundational techniques and tools for unit and integration tests. Along the way, he zooms out to examine how they all fit together. Shaun also highlights TDD's strengths and weaknesses and provides real-world examples that showcase how TDD can fit into your development workflow.

JavaScript 100.00%

test-driven-development's Introduction

JavaScript: Test-Driven-Development (ES6)

TDD is one of the most hotly discussed subjects in the software development world. Even the most carefully constructed applications grow to the point where debugging and ensuring quality becomes difficult. Test-driven development (TDD) helps with this tremendously by ensuring that all parts of your application are covered by tests. In this course, Shaun Wassell explores the foundational techniques and tools for unit and integration tests. Along the way, he zooms out to examine how they all fit together. Shaun also highlights TDD's strengths and weaknesses and provides real-world examples that showcase how TDD can fit into your development workflow.

  • Learning objectives
  • Advantages and disadvantages of TDD
  • The basic TDD cycle
  • The purpose of unit testing
  • Testing basic and asynchronous functions
  • How integration tests fit into TDD
  • JavaScript libraries for integration testing
  • Improving your TDD workflow
  • Checking the test coverage of the codebase

Software Installation

  • node -v // v10.15.1
  • npm -v // 6.6.1
  • npm install
  • Mocha JS // test runner and testing framework
  • Chai // assertion library

Test-Driven Development

Writing tests for your production code before you actually write the production code

  1. The goal of test-driven development is code quality.
  2. There are good and bad tests.
  3. There are many different opinions about the right way to do TDD

Advantages of TDD

  1. TDD forces us to clarify our thinking.
  2. TDD improves communication between developers.
  3. TDD prevents code rot, a slow deterioration of software quality over time.
  4. TDD improves the structure of our production code, to create loosely coupled modular code.
  5. Allows developers to make 'worry-free' changes.

Disadvantages of TDD

  1. TDD takes longer at first.
  2. TDD isn't always a favourite with management.
  3. Beware of writing bad tests!

The basic TDD cycle

  1. [RED] Write a failing test.
  2. [GREEN] Write production code to make the test pass.
  3. [REFACTOR] Refactor the code you wrote.

Writing Good Test

Criteria for a Good Test

  • Readable
  • Isolated
  • Thorough
  • Explicit

3 different types of tests

  • Unit Tests - Test very specific, low-level pieces of functionality
  • Integration Tests - Ensure that the individual pieces of your application work together correctly
  • End-to-End (E2E) Tests - Ensure your entire application works as seen from the viewpoint of a user

The Purpose of Unit Testing

  • Unit tests cover the smallest pieces of functionality: functions.
  • Our test should cover a representative range of inputs.
  • If you can break your production code without breaking your tests, they're not thorough enough.
  • Units tests are you used to test the outcomes of pure functions, functions without states or side effects.

TDD needs 3 basic tools

  1. A testing environment/test runner
  2. A testing framework
  3. An asserting library

Integration Testing

"Mocks" and "stubs" are the most common test doubles. "Don't mock what you don't own." Pure functions equals loosely coupled code.

Categories of Integration test

  1. Single-Service Integration Test
    • Test a single piece, or "service" for your application end to end, independent of the other pieces.
    • Suspectible to Outside Change
  2. Boudary Integration Tests
    • Test the communcation between different pieces of your application.
    • Don't use test double for boundary tests.

REST API

  • GET -> '/users/abc' -> returns { id, username, email } "Status Code OK 200" && Content-type: JSON Header

Next Steps

Learning Functional Programming with JavaScript React: Creating and Hosting a Full-Stack Site React: Testing and Debugging

test-driven-development's People

Contributors

thefishman-fish avatar ibabalola avatar dependabot[bot] avatar

Stargazers

Roman avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.