Convert Figma logo to code with AI

smartystreets logogoconvey

Go testing in the browser. Integrates with `go test`. Write behavioral tests in Go.

8,228
554
8,228
162

Top Related Projects

22,996

A toolkit with common assertions and mocks that plays nicely with the standard library

8,225

A Modern Testing Framework for Go

4,921

Automatically generate Go test boilerplate from your source code.

9,298

GoMock is a mocking framework for the Go programming language.

Quick Overview

GoConvey is a testing tool for Go (Golang) that provides a web UI for viewing test results and a domain-specific language for writing expressive tests. It offers a unique blend of BDD-style assertions and automatic test execution, making it easier to write and manage tests in Go projects.

Pros

  • Intuitive web interface for viewing test results in real-time
  • Expressive DSL for writing readable and maintainable tests
  • Automatic test execution on file changes
  • Seamless integration with Go's built-in testing package

Cons

  • Learning curve for developers unfamiliar with BDD-style testing
  • May introduce additional complexity for simple projects
  • Web UI might be unnecessary for some development workflows
  • Potential performance overhead compared to standard Go testing

Code Examples

  1. Basic assertion:
Convey("Given a simple addition", t, func() {
    result := 2 + 2
    So(result, ShouldEqual, 4)
})
  1. Nested assertions:
Convey("Given a user registration process", t, func() {
    user := RegisterUser("john@example.com", "password123")

    Convey("The user should be created successfully", func() {
        So(user, ShouldNotBeNil)
        So(user.Email, ShouldEqual, "john@example.com")

        Convey("And should have a valid ID", func() {
            So(user.ID, ShouldBeGreaterThan, 0)
        })
    })
})
  1. Custom assertions:
Convey("Testing custom assertions", t, func() {
    So([]int{1, 2, 3}, ShouldContain, 2)
    So("Hello, World!", ShouldStartWith, "Hello")
    So(func() { panic("error") }, ShouldPanic)
})

Getting Started

  1. Install GoConvey:

    go get github.com/smartystreets/goconvey
    
  2. Create a test file (e.g., example_test.go):

    package example
    
    import (
        "testing"
        . "github.com/smartystreets/goconvey/convey"
    )
    
    func TestExample(t *testing.T) {
        Convey("Given a simple test", t, func() {
            So(true, ShouldBeTrue)
        })
    }
    
  3. Run the web UI:

    goconvey
    
  4. Open your browser and navigate to http://localhost:8080 to view the test results.

Competitor Comparisons

22,996

A toolkit with common assertions and mocks that plays nicely with the standard library

Pros of testify

  • More lightweight and focused on assertions and mocking
  • Integrates seamlessly with Go's built-in testing package
  • Provides a rich set of assertion functions for various data types

Cons of testify

  • Lacks built-in test runner with real-time feedback
  • Doesn't offer a web interface for test results visualization
  • May require more setup for complex test scenarios

Code Comparison

testify:

import (
    "testing"
    "github.com/stretchr/testify/assert"
)

func TestSomething(t *testing.T) {
    assert.Equal(t, 123, calculateValue())
}

goconvey:

import (
    "testing"
    . "github.com/smartystreets/goconvey/convey"
)

func TestSomething(t *testing.T) {
    Convey("When calculating a value", t, func() {
        So(calculateValue(), ShouldEqual, 123)
    })
}

testify focuses on providing assertion functions that work with Go's standard testing package, while goconvey offers a more expressive DSL for writing tests and includes additional features like a web UI and automatic test running. testify is generally simpler to set up and use, while goconvey provides a more comprehensive testing experience with its additional tooling.

8,225

A Modern Testing Framework for Go

Pros of Ginkgo

  • More expressive and flexible test structure with nested contexts and descriptions
  • Built-in support for asynchronous testing and parallel test execution
  • Comprehensive suite of matchers and assertion functions

Cons of Ginkgo

  • Steeper learning curve due to its DSL and more complex syntax
  • May be overkill for simple projects or smaller codebases
  • Requires additional setup and configuration compared to GoConvey

Code Comparison

Ginkgo:

var _ = Describe("Calculator", func() {
    It("adds two numbers", func() {
        result := Add(2, 3)
        Expect(result).To(Equal(5))
    })
})

GoConvey:

Convey("Given a Calculator", t, func() {
    Convey("When adding two numbers", func() {
        result := Add(2, 3)
        So(result, ShouldEqual, 5)
    })
})

Both Ginkgo and GoConvey are popular testing frameworks for Go, offering different approaches to writing and organizing tests. Ginkgo provides a more feature-rich and expressive testing environment, while GoConvey focuses on simplicity and ease of use. The choice between the two depends on project requirements, team preferences, and the complexity of the testing scenarios.

4,921

Automatically generate Go test boilerplate from your source code.

Pros of gotests

  • Automatically generates table-driven tests, reducing boilerplate code
  • Integrates well with existing Go tooling and IDEs
  • Focuses on generating test skeletons, allowing developers to fill in test logic

Cons of gotests

  • Lacks built-in assertion functions, requiring additional libraries or manual comparisons
  • Does not provide a web-based UI for test results visualization
  • Limited to generating unit tests, without support for BDD-style testing

Code Comparison

gotests generated test:

func TestSum(t *testing.T) {
    tests := []struct {
        name string
        a    int
        b    int
        want int
    }{
        // TODO: Add test cases.
    }
    for _, tt := range tests {
        t.Run(tt.name, func(t *testing.T) {
            if got := Sum(tt.a, tt.b); got != tt.want {
                t.Errorf("Sum() = %v, want %v", got, tt.want)
            }
        })
    }
}

GoConvey test:

Convey("Given two numbers", t, func() {
    Convey("When summing them", func() {
        result := Sum(2, 3)
        Convey("The result should be correct", func() {
            So(result, ShouldEqual, 5)
        })
    })
})

GoConvey provides a more expressive, BDD-style syntax with built-in assertions, while gotests generates a table-driven test structure that developers need to populate with test cases and assertions manually.

9,298

GoMock is a mocking framework for the Go programming language.

Pros of mock

  • Focused specifically on mocking, providing a robust solution for creating mock objects
  • Integrated with Go's built-in testing package, allowing seamless use within existing test suites
  • Supports method stubbing and expectation setting with a fluent API

Cons of mock

  • Lacks built-in assertion functions, requiring additional libraries for complex assertions
  • Does not provide a web UI for test results visualization
  • Learning curve may be steeper for beginners compared to GoConvey's more intuitive syntax

Code Comparison

GoConvey:

Convey("When dividing by zero", t, func() {
    So(func() { Divide(1, 0) }, ShouldPanic)
})

mock:

ctrl := gomock.NewController(t)
defer ctrl.Finish()
mockObj := NewMockInterface(ctrl)
mockObj.EXPECT().SomeMethod(gomock.Any()).Return(42)

Summary

While mock excels in creating mock objects and integrating with Go's testing package, GoConvey offers a more comprehensive testing framework with a user-friendly syntax and web UI. mock is ideal for projects requiring extensive mocking, while GoConvey may be preferred for its readability and visual test results. The choice between the two depends on specific project needs and team preferences.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

SMARTY DISCLAIMER: Subject to the terms of the associated license agreement, this software is freely available for your use. This software is FREE, AS IN PUPPIES, and is a gift. Enjoy your new responsibility. This means that while we may consider enhancement requests, we may or may not choose to entertain requests at our sole and absolute discretion.

GoConvey is awesome Go testing

Build Status GoDoc

Welcome to GoConvey, a yummy Go testing tool for gophers. Works with go test. Use it in the terminal or browser according to your viewing pleasure.

GoConvey supports the current versions of Go (see the official Go release policy). Currently this means Go 1.16 and Go 1.17 are supported.

Features:

  • Directly integrates with go test
  • Fully-automatic web UI (works with native Go tests, too)
  • Huge suite of regression tests
  • Shows test coverage
  • Readable, colorized console output (understandable by any manager, IT or not)
  • Test code generator
  • Desktop notifications (optional)
  • Immediately open problem lines in Sublime Text (some assembly required)

You can ask questions about how to use GoConvey on StackOverflow. Use the tags go and goconvey.

Menu:

Installation

$ go install github.com/smartystreets/goconvey

Quick start

Make a test, for example:

package package_name

import (
    "testing"
    . "github.com/smartystreets/goconvey/convey"
)

func TestSpec(t *testing.T) {

	// Only pass t into top-level Convey calls
	Convey("Given some integer with a starting value", t, func() {
		x := 1

		Convey("When the integer is incremented", func() {
			x++

			Convey("The value should be greater by one", func() {
				So(x, ShouldEqual, 2)
			})
		})
	})
}

In the browser

Start up the GoConvey web server at your project's path:

$ $GOPATH/bin/goconvey

Then watch the test results display in your browser at:

http://localhost:8080

If the browser doesn't open automatically, please click http://localhost:8080 to open manually.

There you have it. As long as GoConvey is running, test results will automatically update in your browser window.

The design is responsive, so you can squish the browser real tight if you need to put it beside your code.

The web UI supports traditional Go tests, so use it even if you're not using GoConvey tests.

In the terminal

Just do what you do best:

$ go test

Or if you want the output to include the story:

$ go test -v

Documentation

Check out the

  • GoConvey wiki,
  • GoDoc
  • and the *_test.go files scattered throughout this project.

Contributors

GoConvey is brought to you by SmartyStreets and several contributors (Thanks!).