Take on a better unit test style

This page summarizes the projects mentioned and recommended in the original post on /r/golang

Our great sponsors
  • InfluxDB - Power Real-Time Data Analytics at Scale
  • WorkOS - The modern identity platform for B2B SaaS
  • SaaSHub - Software Alternatives and Reviews
  • testify

    This is a fork of github.com/stretchr/testify, we upstream as much as possible (by symflower)

  • We were unhappy with the common unit test styles and we think we found a style that has clear advantages. An in-depth comparison can be found here https://symflower.com/en/company/blog/2022/better-table-driven-testing/ We also added support for maintaining such tests in our VS Code extension https://marketplace.visualstudio.com/items?itemName=symflower.symflower You can either use the command or the context menu item to maintain tests. There are some changes necessary to have better stack traces because "t.Run" calls the test function from another location. We are in the process of upstreaming them. Until then you can find these changes in our fork at https://github.com/symflower/testify Would appreciate your feedback on the style and extension. Would be also interesting to hear other approaches and conventions that could help others to write better tests.

  • autogold

    Automatically update your Go tests

  • prefer these two tools: https://github.com/maxbrunsfeld/counterfeiter and https://github.com/hexops/autogold

  • InfluxDB

    Power Real-Time Data Analytics at Scale. Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.

    InfluxDB logo
  • dockertest

    Write better integration tests! Dockertest helps you boot up ephermal docker images for your Go tests with minimal work.

  • also if not using repository pattern, I prefer using https://github.com/ory/dockertest

  • consul

    Consul is a distributed, highly available, and data center aware solution to connect and configure applications across dynamic, distributed infrastructure.

  • Interesting! I independently arrived at almost the same pattern while working on tests in https://github.com/hashicorp/consul.

  • gotests

    Automatically generate Go test boilerplate from your source code.

  • Did you encounter gotests when you were doing your research? It's a table test generation tool that generates test code using t.Run(). I do wish it could generate tests using testify, because I frequently end up rewriting the code in the inner loop, but I still use it because it's better than I am about ensuring there's a test for all functions I write.

  • testeach

    Simple test setup/teardown for Go tests

  • As another alternative, sorry for the plug, I created this tiny library for structuring tests: https://github.com/devnev/testeach A bit more like BDD but I've found it quite nice to with with

NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts