Russ Cox: Go Testing by Example

This page summarizes the projects mentioned and recommended in the original post on news.ycombinator.com

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

    Go by Example

  • Some similar resources I like:

    "Learn Go with Tests" book: https://quii.gitbook.io/learn-go-with-tests

    "Go by Example": https://gobyexample.com/

  • testy

    test helpers for more meaningful, readable, and fluent tests

  • Agreed with most of this but I’m skeptical of the rsc.io/script dsl approach. I’ll try it, though, because Russ is often right.

    shameless advert: do you wish testify was implemented with generics and go-cmp, and had a more understandable surface area? Check out my small zero-dep library, Testy https://github.com/peterldowns/testy

    shameless advert: do you want to write tests against your postgres database, but each new test adds seconds to your test suite? Check out pgtestdb, the marginal cost of each test is measured in tens of milliseconds, and each test gets a unique and isolated postgres instance — with all your migrations applied. https://github.com/peterldowns/pgtestdb

  • 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
  • pgtestdb

    quickly run tests in their own temporary, isolated, postgres databases

  • Agreed with most of this but I’m skeptical of the rsc.io/script dsl approach. I’ll try it, though, because Russ is often right.

    shameless advert: do you wish testify was implemented with generics and go-cmp, and had a more understandable surface area? Check out my small zero-dep library, Testy https://github.com/peterldowns/testy

    shameless advert: do you want to write tests against your postgres database, but each new test adds seconds to your test suite? Check out pgtestdb, the marginal cost of each test is measured in tens of milliseconds, and each test gets a unique and isolated postgres instance — with all your migrations applied. https://github.com/peterldowns/pgtestdb

  • gotests

    Automatically generate Go test boilerplate from your source code.

  • A huge time-saver for me when generating table-driven test boilerplate in Go has been using gotests[0] to generate the template.

    If you use VSCode with the Go extension it's already available there as a command "Go: Generate Unit Tests for Function/Package".

    [0] https://github.com/cweill/gotests

  • dotfiles

    My dotfiles, managed with https://chezmoi.io. (by twpayne)

  • chezmoi (<https://chezmoi.io> or <https://github.com/twpayne/chezmoi>) has a couple dozen txtar tests. They are both amazing and completely frustrating to use, but I don't think that there would be a better way to test most of what chezmoi does without them.

    Tom Payne (the creator and primary developer of chezmoi) has added some extra commands to the txtar context which makes things easier for certain classes of testing.

  • chezmoi

    Manage your dotfiles across multiple diverse machines, securely.

  • chezmoi (<https://chezmoi.io> or <https://github.com/twpayne/chezmoi>) has a couple dozen txtar tests. They are both amazing and completely frustrating to use, but I don't think that there would be a better way to test most of what chezmoi does without them.

    Tom Payne (the creator and primary developer of chezmoi) has added some extra commands to the txtar context which makes things easier for certain classes of testing.

  • Txtar

    Swift implementation of a txtar parser and formatter.

  • WorkOS

    The modern identity platform for B2B SaaS. The APIs are flexible and easy-to-use, supporting authentication, user identity, and complex enterprise features like SSO and SCIM provisioning.

    WorkOS logo
  • skeema

    Declarative pure-SQL schema management for MySQL and MariaDB

  • Using tmpfs for MySQL/MariaDB's data directory helps tremendously. If you're using Docker natively on Linux, use `docker run --tmpfs /var/lib/mysql ...` and that'll do the trick. Only downside is each container restart is slightly slower due to having to re-init the database instance from scratch.

    Tuning the database server settings can help a lot too. You can add overrides to the very end of your `docker run` command-line, so that they get sent as command-line args to the database server. For example, use --skip-performance-schema to avoid the overhead of performance_schema if you don't need it in your test/CI environment.

    For MySQL 8 in particular, I've found a few additional options help quite a lot: --skip-innodb-adaptive-hash-index --innodb-log-writer-threads=off --skip-log-bin

    A lot of other options may be workload-specific. My product Skeema [1] can optionally use ephemeral containerized databases [2] for testing DDL and linting database objects, so the workload is very DDL-heavy, which means the settings can be tuned pretty differently than a typical DML-based workload.

    [1] https://github.com/skeema/skeema/

    [2] https://www.skeema.io/docs/options/#workspace

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