Skip to content

Go guide: be more explicit on testing frameworks + diffing test results

Description of the proposal

It's difficult to identify problems and debug tests when they just output the expected and actual value. It becomes especially annoying when it comes to comparing large portions of text, JSON, or complex Go structs.

The idea is borrowed from beautiful RSpec matchers. Let's bring diff-like output to comparing the expected/actual values in tests.

Development log

Status

  • Mention the proposal in the next backend weekly call and the #backend channel to encourage contribution
  • Proceed with the proposal once 50% of the maintainers have weighed in, and 80% of the votes are 👍
  • Once approved, mention it again in the next backend weekly call and the #backend channel

Decisions

  • tried the cmp.Diff function and found that it does its job
    • pros:
      • diff-like output: easy to identify and fix errors
      • supported by Google and well-documented
    • cons:
      • the output of cmp.Diff is unstable from one run to another; if one won't try consuming it programmatically and make assumptions on its content, we should be fine
      • it would become another dependency for all of our Go projects; we must evaluate the alternatives carefully in terms of the license, performance, community support, security issues, etc.
  • it has been realized that testify is already used across a number of our projects; explored its matchers' diffing capabilities
  • decided to go for testify/require#Equal for consistency, updated the proposal to be more explicit on that
Edited by Victor Zagorodny

Merge request reports