Giter Site home page Giter Site logo

bad-units's Introduction

Bad Unit

A number of examples that show bad practices seen in unit tests. Examples are written in Ruby with RSpec and Java with JUnit.

There may not be a corresponding code example.

Test Always Passes

The assert will just assert that true is equal to true, thereby passing the test regardless of what has happened.

Test name doesn't describe what test does

The test name is a summary of what the test is checking. If it is not describing it correctly, you are making life difficult for the poor soul who ends up debugging it (and there is a non-zero chance that person will be you!).

Test is checking more than one thing

Unit tests should follow the Assign (Given) Act (When) Assert (Then) model. No actions should be done after an assertion. This indicates you are doing more than one test.

Errors not being caused by the unit you are testing

When checking that an error is being thrown, make sure the error is coming from the bit you are actually testing and not in a setup step. If anything other than the code you are testing may throw the error you are checking, surround in try/catch blocks and throw another error instead.

Mocking Data Storage Objects

Examples of data storage objects are classes that only consist of getters and setters, or hashs, maps arrays etc. Only use mocks to bypass or control the results of methods that perform some kind of logic operation (e.g. mock methods that have if statements).

bad-units's People

Contributors

testingchef avatar dependabot[bot] avatar

Watchers

 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.