Giter Club home page Giter Club logo

go-tdd's Introduction

Test Driven Development

Usage

go test

go test -cover
go test -coverprofile=result.out
go tool cover -html=result.out -o result.html

Good practices

Do this...

  1. Follow TDD steps: write test, write code, improve test, improve code and iter!
  2. Use interfaces.
  3. Use Table Driven Tests (TDT).
  4. Use go native libraries.
  5. Build tests of differents packages.
  6. Do not change the behaviour of your tests (do not change your tests) when refactor the code.
  7. Do not forget integration tests.

Antipatterns

Do not do this...

  1. Giving confusing information when a test fails. Solution: be explicit and give context when tests fails.
  2. If your code is difficult to test, your code is difficult to use. Solution: make easy and clean code.
  3. Not following the typical structure of a test. Solution: write setup and preconditions, then actions, follow with assertions and finally clean and tier down. Do not mix this steps!
  4. Prefer DRY (dont repeat yourself) to DAMP (descriptive and meaningful phrases). Solution: repeat code if you need. Make a very smart test could make it complicated to understand.
  5. Include error cases in Table Driven Tests. Solution: create tests cases for testing errors.
  6. Violate encapsulation. Solution: do not make public methods, attributes, constants, etc only cause you need it on tests. Build a simple interfaces and methods.

go-tdd's People

Contributors

feliux 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.