Finding Your Best Go Testing Framework

A comprehensive guide to the top Go testing frameworks

Denis Peganov
8 min readApr 3, 2023
Source: https://github.com/marcusolsson/gophers/blob/master/gopherdata-gopher.png

Table of contents

Brief frameworks overview
Testify
Ginkgo
GoConvey
Godog
So which testing framework is the best?

Brief frameworks overview

With the rise in popularity of the Go programming language, it’s more important than ever to choose the right testing framework for your projects. Go’s simplicity, speed and concurrency make it an attractive option for building scalable and high-performance applications, but without proper testing bugs and errors can quickly derail even the most well-designed projects.

Fortunately, there are a number of powerful testing frameworks available for Go that provide a range of features and functionality to help write effective and efficient tests. We’ll compare the most popular of them, so you make an informed decision about which one is best for your specific testing needs and preferences.

Let’s start with a very short overview of testing frameworks covered in this article:

  1. Testify
    Features: Assertion functions, mocking and suite-based testing.
    GitHub stars: 7.100+
    Last update: August 2021
  2. Ginkgo
    Features: BDD-style syntax, parallel testing and expressive assertions using Gomega.
    GitHub stars: 4.700+
    Last update: January 2022
  3. GoConvey
    Features: web-based UI for viewing test results, easy continuous integration setup and code coverage analysis.
    GitHub stars: 3.800+
    Last update: November 2020
  4. Godog
    Features: BDD-style syntax, step definitions, and integration with Gherkin syntax.
    GitHub stars: 1.300+
    Last update: December 2021

Before diving into the specific features and benefits of each go testing framework, it’s important to understand that testing helps ensure that your code works as intended, catches bugs and errors before they become major issues, and improves the overall quality of your product. By investing time and effort into testing, you can save yourself and your team a lot of headaches down the road. With that in mind, selecting the right testing framework for your project is essential, so I will provide you with the information which might help you to choose the right one for your project.

Testify

Testify provides a range of assertion functions that allow you to test various conditions in your code. For example, you can use the assert.Equal function to compare two values and ensure that they are equal. You can also use the assert.NoError function to ensure that a function call does not return an error.

Testify also provides support for structuring your tests into test suites and includes support for teardown functions that can clean up resources after a test has run.

The syntax for using Testify is simple and easy to understand. You start by importing the Testify package into your test file, and then you can use the various assertion functions to write your tests.

Features and Benefits

  • Provides a range of assertion functions, making it easy to write clear and concise tests.
  • Offers support for test suite structuring and teardown functions.
  • Works with Go’s native testing package, making it easy to integrate with your existing testing code.
  • Provides useful error messages that help you quickly identify and fix issues in your code.
  • Easy to learn and use, even for developers new to Go testing.

Example

Pros and Cons

  • Pros of using Testify include its range of assertion functions, ease of use and useful error messages. Additionally, Testify works well with Go’s native testing package, making it easy to integrate with existing testing code.
  • Cons of using Testify include the lack of support for behavior-driven development (BDD) style testing and the fact that it can sometimes be difficult to find the right assertion function to use for a particular test.

Ginkgo

Ginkgo uses a BDD-style syntax that allows you to write tests in a natural language format. For example, you can use the Describe function to describe a set of tests, and then use the It function to define individual tests within that set. You can also use the BeforeEach and AfterEach functions to set up and tear down resources for each test.

Ginkgo also offers support for asynchronous testing, allowing you to test code that involves concurrency using the Eventually and Consistently functions.

Features and Benefits

  • Provides a BDD-style syntax, making it easy to write tests that are readable and easy to understand.
  • Offers support for asynchronous testing, making it easy to test code that involves concurrency.
  • Includes support for nested contexts and assertions, making it easy to organize and structure your tests.
  • Provides helpful error messages that make it easy to identify and fix issues in your code.
  • Offers support for custom reporters, allowing you to customize the output of your tests.

Example

Pros and Cons

  • Pros of using Ginkgo include its BDD-style syntax, support for asynchronous testing, and its ability to organize and structure tests using nested contexts and assertions. Additionally, Ginkgo provides helpful error messages that make it easy to identify and fix issues in your code.
  • Cons of using Ginkgo include the fact that it can sometimes be difficult to get started with if you’re not familiar with BDD-style testing, and that it may not be the best choice for simple, straightforward tests.

GoConvey

GoConvey uses a BDD-style syntax that allows you to write tests in a natural language format. For example, you can use the Convey function to describe a set of tests, and then use the So function to define individual tests within that set. You can also use the BeforeEach and AfterEach functions to set up and tear down resources for each test.

Features and Benefits

  • Provides a web-based UI for viewing test results, making it easy to visualize the status of your tests.
  • Offers support for behavior-driven development (BDD) style testing, making it easy to write tests that are readable and easy to understand.
  • Includes support for live code reloading, allowing you to see the results of your changes in real-time.
  • Provides a range of assertion functions, making it easy to write clear and concise tests.
  • Offers support for running tests in parallel, allowing you to speed up your test runs.

Example

Pros and Cons

  • Pros of using GoConvey include its web-based UI for viewing test results, support for BDD-style testing and live code reloading. Additionally, GoConvey provides a range of assertion functions that make it easy to write clear and concise tests.
  • Cons of using GoConvey include the fact that it can be difficult to integrate with existing testing code that uses Go’s native testing package, and that it may not be the best choice for simple, straightforward tests. Additionally, the web-based UI can sometimes be slow or unresponsive, especially when running a large number of tests.

Godog

Godog uses a BDD-style syntax that allows you to write tests in a natural language format. You can define your tests using feature files that describe the behavior you want to test, and then define step definitions that map to the steps in your feature files. Godog provides a range of built-in step definitions that you can use, and you can also define your own custom step definitions if needed.

Features and Benefits

  • Supports behavior-driven development (BDD) style testing, which makes it easy to write tests that are readable and easy to understand.
  • Provides a simple, intuitive syntax for defining feature files and step definitions, which makes it easy to get started with testing right away.
  • Offers integration with popular testing tools like Cucumber and Gherkin, making it easy to transition from those tools to Godog.
  • Provides detailed error reporting, which makes it easy to pinpoint issues in your tests.
  • Offers support for running tests in parallel, allowing you to speed up your test runs.

Example

In the above example, we’re defining a feature file that describes a scenario for adding two numbers. We define each step in the scenario using Given, When and Then keywords, and then map those steps to step definitions in our code:

As I said, we defined step definitions that map to the steps in our feature file. We define each step using a regular expression that matches the step text, and then define a function that executes the step. Inside each step function, we can perform any necessary actions or assertions.

Pros and Cons

  • Pros of using Godog include its support for BDD-style testing, simple syntax and detailed error reporting. Additionally, Godog provides integration with popular testing tools like Cucumber and Gherkin, making it easy to transition from those tools to Godog.
  • Cons of using Godog include the fact that it can be slower than other testing frameworks due to its use of regular expressions, and that it may not be the best choice for small or simple test suites. Additionally, the syntax for defining step definitions can be verbose, especially for complex scenarios.

So which testing framework is the best?

I know that you came here to find it out and I won’t surprise you if I just say it’s difficult to make a decision without knowing your specific needs and preferences. However, I’ve prepared some general guidelines that might help you:

  • If you’re looking for a framework that is easy to learn and use, Testify might be a good choice. Its simple syntax and comprehensive set of assertion functions make it a great choice for beginners.
  • Looking for a highly expressive testing framework that supports nested test groups and parallel test execution: Ginkgo might be a good choice. Its expressive syntax and support for parallel test execution make it a great choice for complex test suites.
  • Need a framework that provides a visual, web-based user interface for running and viewing test results? GoConvey might be a good choice. Its web-based interface and support for live reloading make it a great choice for teams who want to easily collaborate on testing.
  • Finally, if you’re looking for a framework that supports behavior-driven development (BDD) style testing, Godog might be a good choice. Its support for BDD-style testing makes it easy to write tests that are easy to understand and can be used to document your code.

Ultimately, the best testing framework for your project will depend on your specific needs and preferences. It may be worth trying out several frameworks and seeing which one works best for you and your team.

Eventually, I hope that this article has provided you with a helpful overview of Testify, Ginkgo, GoConvey and Godog with their features and benefits as testing frameworks for Go. By comparing and contrasting these frameworks, you can make an informed decision about which one is best suited for your project’s unique needs and requirements.

Each of these frameworks has its own strengths and limitations, and understanding their differences can help you save time and resources in the testing process, improve the quality of your code, and ultimately deliver a better end product. As you continue to explore the world of Go testing, it’s essential to keep experimenting with different frameworks and testing strategies, to keep your skills sharp and up-to-date with the latest developments in software testing.

--

--

Denis Peganov

Hey, I'm a QA Engineer dedicated to ensuring the quality of multiple products, and I'm passionate about sharing my expertise and insights with the community.