All Projects β†’ devcorpio β†’ the-art-of-unit-testing

devcorpio / the-art-of-unit-testing

Licence: MIT license
Repository that contains code in Node.js from the book The Art of Unit Testing, Second Edition by Roy Osherove

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to the-art-of-unit-testing

React Cool Starter
😎 🐣 A starter boilerplate for a universal web app with the best development experience and a focus on performance and best practices.
Stars: ✭ 1,083 (+4822.73%)
Mutual labels:  unit-testing, prettier
Express React Boilerplate
πŸš€πŸš€πŸš€ This is a tool that helps programmers create Express & React projects easily base on react-cool-starter.
Stars: ✭ 32 (+45.45%)
Mutual labels:  unit-testing, prettier
microbundle-ts-pkg
A TypeScript npm package skeleton/starter project with microbundle, node:test and prettier
Stars: ✭ 20 (-9.09%)
Mutual labels:  prettier
create-next-stack
Create Next Stack is a website and CLI tool used to easily set up the boilerplate of new Next.js apps.
Stars: ✭ 149 (+577.27%)
Mutual labels:  prettier
testza
Full-featured test framework for Go! Assertions, fuzzing, input testing, output capturing, and much more! πŸ•
Stars: ✭ 409 (+1759.09%)
Mutual labels:  unit-testing
UTBotCpp
Tool that generates unit test by C/C++ source code, trying to reach all branches and maximize code coverage
Stars: ✭ 59 (+168.18%)
Mutual labels:  unit-testing
Dilettantes-Guide-to-Linting
Setting up ESLint, Prettier, VS Code, and the AirBnB style guide in beautiful harmony.
Stars: ✭ 18 (-18.18%)
Mutual labels:  prettier
toster
DSL framework for testing Android apps
Stars: ✭ 31 (+40.91%)
Mutual labels:  unit-testing
prettier.el
Prettier code formatting for Emacs.
Stars: ✭ 129 (+486.36%)
Mutual labels:  prettier
chai-exclude
Exclude keys to compare from a deep equal operation with chai expect or assert.
Stars: ✭ 33 (+50%)
Mutual labels:  unit-testing
Tablier
A micro-framework for Table Driven Tests.
Stars: ✭ 33 (+50%)
Mutual labels:  unit-testing
MinimalApi
ASP.NET Core 7.0 - Minimal API Example - Todo API implementation using ASP.NET Core Minimal API, Entity Framework Core, Token authentication, Versioning, Unit Testing, Integration Testing and Open API.
Stars: ✭ 156 (+609.09%)
Mutual labels:  unit-testing
dumbmutate
Simple mutation-testing
Stars: ✭ 32 (+45.45%)
Mutual labels:  unit-testing
invig
🌿 Invig automatically converts ES5 & CoffeeScript codebases to ES6 with Aligned JavaScript Standard Style
Stars: ✭ 62 (+181.82%)
Mutual labels:  prettier
jasmine-styleguide
Suggested best practices when writing Jasmine unit tests.
Stars: ✭ 65 (+195.45%)
Mutual labels:  unit-testing
promotion-web
基于React: v18.x.x/Webpack: v5.x.x/React Router v6.x.x/ Antd: v5..x.x/Fetch Api/ Typescript: v4.x.x η­‰ζœ€ζ–°η‰ˆζœ¬θΏ›θ‘Œζž„ε»Ί...
Stars: ✭ 374 (+1600%)
Mutual labels:  prettier
EntityFrameworkCore.AutoFixture
A library aimed to minimize the boilerplate required to unit-test Entity Framework Core code using AutoFixture and in-memory providers.
Stars: ✭ 31 (+40.91%)
Mutual labels:  unit-testing
ultimate-hot-boilerplate
πŸš€ node-react universal app boilerplate with everything on hot reload, SSR, GraphQL, Flow included
Stars: ✭ 35 (+59.09%)
Mutual labels:  prettier
webpack-boilerplate
Webpack 4 boilerplate (babel, eslint, prettier, jest, sass, postcss, hmr, browsersync)
Stars: ✭ 33 (+50%)
Mutual labels:  prettier
pythonista-chromeless
Serverless selenium which dynamically execute any given code.
Stars: ✭ 31 (+40.91%)
Mutual labels:  unit-testing

The Art of Unit Testing, Second Edition

The Art of Unit Testing, Second Edition

The Art of Unit Testing is a book written by Roy Osherove

The book code examples are written in C# and the tools that appears in it are from the .NET community.

Goal of this repository

Node.js

I would like that people that works using Node.js could enjoy of the knowledge that this book offers to its readers. Therefore I going to use Node.js to write the code examples and I going to use tools typically related with it. 😍

The style of the code and the chosen tools are 100% my decision. (The good and the bad parts! 😚)

How study the repository

  1. For every chapter of the book has I created a directory where appears the final version of the code in the mentioned chapter.

  2. Every commit has a reference to the chapter related. Any change I needed to do has a commit, with the objective of follow the flow of the book.

Note: If you want to open the links in another tab, just do a CTRL+click on the link.

Chapters

  1. The basics of unit testing

    git commits done during the chapter :shipit:

    - Initial commit
    - In order to commit formatted code I installed prettier, pretty-quick and husky
    - update README
    - preparing the simpleParser example, creating InvalidOperation custom error
    - creating simpleParser example
    - creating a test manually to do basic tests to simpleParser, I'm not using unit testing frameworks, yet

  2. A first unit test

    git commits done during the chapter :shipit:

    - starting LogAn, the project that we are going to use in the next chapters
    - install jest
    - renaming homemade test of the chapter 01 to avoid conflicts with jest
    - creating logAnalyzer and its test, that show us that the SUT have a bug
    - fix isValidLogFileName in order to fix the test
    - adding two more tests, one of them intetionally fails
    - fix in isValidLogFilename to fix the test
    - refactoring the code of thest using the parameterized tests technique
    - adding setup to the test
    - returns error if the filename is empty
    - add test that assert that the error is thrown
    - adding state logAnalyzer
    - first state-based test for logAnalyzer
    - add a inmemory calculator to continuing trying state-based testing
    - add a memory calculator in order to test it with state-based testing
    - update readme
    - remove .vscode from repository

  3. Using stubs to break dependencies

    git commits done during the chapter :shipit:

    - copy code from chapter 02 to the chapter 03 folder in order to continue with the book
    - install @types/node, with that, I can work with types and node.js modules without vscode warnings
    - check the validity of the file extension in a disk file, that creates an external dependency, unit tests are broken
    - fixing logAnalyzer tests, right now they are integration tests and not unit tests, meh
    - extracting a factory function that touches the filesystem and calling it
    - creating a fake extension manager, the name of a fake is because we can use it as a stub or a mock, depending of the test.
    - create a new fake that is ready to be configurable to use in test
    - fixing alwaysValidFakeExtensionManager, I didn't create the function return
    - I created a seam in logAnalyzer, that seam enable the possibility of inject the dependency while are calling the function
    - using the fakeManagerExtension to fix the failed test from the previous commit
    - creating a extension manager factory that allows to set the extension manager to return before execute it, the default manager it returns is fileExtensionManager
    - using extensionManagerFactory I created an integration test, because the test is making use of a external dependency, the filesystem
    - using extensionManagerFactory I created an unit test, because the test is making use of a fake extension manager, therefore I'm not using the filesystem that is an external dependency
    - I have changed the isValid method from the fakes to return a promise instead of a boolean
    - In order to use the technique Extract and Override I needed to create a new file using logAnalyzer as a class and create a virtual method
    - testing the the new class using the technique Extract and Override

  4. Interaction testing using mock objects

    git commits done during the chapter :shipit:

    - copy code from chapter 03 to the chapter 04 folder in order to continue with the book
    - organizing a bit more the files to improve the 'first glance' effect of LogAn folder
    - create a new object that fake a call to a web service
    - create a basic webservice in order to create an example that I want to create from the book
    - adding a parameter that allows to pass an object webService to logAnalyzer
    - creating the real webService connector
    - fixing fakeWebService, create getter and return both object with the two functions
    - create a unit test that use fakeWebService as a mock
    - adding another fake named emailService, and create a new test where the webService is used as stub and the emailService as a mock

  5. Isolation (mocking) frameworks

    git commits done during the chapter :shipit:

    - copy logAnalyzer.js, errors and fakes from the folder of chapter 04 in order to continue with the book
    - creating a test that use a fake handwritten
    - instead of use a handwriting fake I create it using jest mocking module!
    - check that the logError method is called with the expected error message using jest mocking system functions

  6. Digging deeper into isolation frameworks

    git commits done during the chapter :shipit:

    No commits here, this chapter go deep in the explanation about isolation frameworks, interesting concepts! 😁

  7. test hierarchies and organization

    git commits done during the chapter :shipit:

    - initial code to create a test api for the application, the name of the first strategy is abstract test infrastructure class pattern
    - refactored solution based in abstract test infrastructure class pattern

    • Also Wonderful explanations about concepts as:

      1. Focus in the importance of separation of unit tests and integration tests.
      2. Separate them by speed: slows, fasts, etc
      3. Create nightly builds, CI builds, etc
      4. More and more 😁 if you want to know all, buy the book

  8. The pillars of good unit tests

    git commits done during the chapter :shipit:

    - No commits here, in this chapter Roy speaks deeply about:

     1. Writing trustworthy tests
     2. Writing maintainable tests
     3. Writing readable tests
     4. Exploring naming conventions for unit tests.
    

    Thanks to the content of this chapter I have said to myself many times "aha", this chapter by itself triggers a message,and the message is: "buy the book!" 😁 I enjoyed a lot this chapter.

  9. Integration unit testing into the organization

    git commits done during the chapter :shipit:

    - No commits here, wonderful chapter!, this book is a drug for me(a good drug!) πŸ˜„

  10. Working with legacy code

    git commits done during the chapter :shipit:

    - No commits here, several amazing concepts! πŸ˜„ πŸ˜„

  11. Design and testability

    git commits done during the chapter :shipit:

    - No commits here. I finished the read and study of the book, to read this book should be a must in my opinion

😁 😁 😁

How to use

Setup

Install all the dependencies:

npm install

If you want to execute the all tests I created:

npm run test

Final thoughts

I hope you enjoy the repository as much I while I was writing it πŸ˜ƒ

I strongly encourage that you should buy the book, it is a masterpiece.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].