Top Related Projects
Quick Overview
"is" is a professional lightweight testing mini-framework for Go. It provides a set of assertion functions that make writing tests more expressive and readable. The library aims to simplify test writing while maintaining clarity and reducing boilerplate code.
Pros
- Simple and intuitive API for writing expressive tests
- Lightweight with no external dependencies
- Supports custom failure messages and error reporting
- Compatible with Go's built-in testing package
Cons
- Limited set of assertion functions compared to some larger testing frameworks
- May require additional setup for more complex testing scenarios
- Not as feature-rich as some alternative testing libraries
- Lacks some advanced features like test generation or benchmarking tools
Code Examples
- Basic assertion:
func TestSomething(t *testing.T) {
is := is.New(t)
result := SomeFunction()
is.Equal(result, expectedValue) // checks if result equals expectedValue
}
- Checking for errors:
func TestErrorHandling(t *testing.T) {
is := is.New(t)
_, err := SomeFunctionThatMightError()
is.NoErr(err) // asserts that err is nil
}
- Custom failure message:
func TestWithCustomMessage(t *testing.T) {
is := is.New(t)
value := 42
is.Equal(value, 43, "value should be 43") // provides a custom failure message
}
Getting Started
To use "is" in your Go project, follow these steps:
-
Install the package:
go get github.com/matryer/is
-
Import it in your test file:
import "github.com/matryer/is"
-
Create an
is
instance in your test function:func TestExample(t *testing.T) { is := is.New(t) // Use is.Equal(), is.NoErr(), etc. for assertions }
Competitor Comparisons
A toolkit with common assertions and mocks that plays nicely with the standard library
Pros of testify
- More comprehensive suite of testing tools, including mocking and suite support
- Higher adoption rate and larger community
- More frequent updates and maintenance
Cons of testify
- Steeper learning curve due to more features and complexity
- Larger codebase and dependencies
Code Comparison
testify:
assert := assert.New(t)
assert.Equal(expected, actual, "they should be equal")
assert.NotNil(object)
assert.True(condition)
is:
is := is.New(t)
is.Equal(expected, actual)
is.NotNil(object)
is.True(condition)
Summary
testify offers a more feature-rich testing experience with broader community support, while is provides a simpler, more straightforward approach. testify's assertion syntax is slightly more verbose but offers more descriptive error messages. is focuses on simplicity and ease of use, with a more concise syntax.
Both libraries are well-maintained and suitable for Go testing, with the choice depending on project requirements and developer preferences. testify is better suited for larger projects requiring advanced testing features, while is may be preferable for smaller projects or developers seeking a minimalist approach.
Ginkgo's Preferred Matcher Library
Pros of Gomega
- More extensive and feature-rich assertion library
- Better support for asynchronous testing
- Integrates well with the Ginkgo BDD testing framework
Cons of Gomega
- Steeper learning curve due to more complex API
- Slightly more verbose syntax for simple assertions
- Requires importing multiple packages for full functionality
Code Comparison
Gomega:
Expect(someValue).To(Equal(expectedValue))
Expect(someSlice).To(HaveLen(3))
Expect(someFunction()).To(Succeed())
Is:
is.Equal(t, someValue, expectedValue)
is.Equal(t, len(someSlice), 3)
is.NoErr(t, someFunction())
Summary
Gomega offers a more comprehensive set of features and better support for complex testing scenarios, particularly when used with Ginkgo. However, it comes with a steeper learning curve and more verbose syntax for simple assertions. Is provides a simpler, more straightforward API that's easier to pick up and use for basic testing needs. The choice between the two depends on the complexity of your testing requirements and personal preference for API style.
Package for comparing Go values in tests
Pros of go-cmp
- More comprehensive and flexible comparison options
- Better support for custom types and complex structures
- Actively maintained by Google, with regular updates
Cons of go-cmp
- Steeper learning curve due to more complex API
- Requires more setup and configuration for custom comparisons
- Slightly more verbose syntax for simple comparisons
Code Comparison
is:
is.Equal(t, got, want)
is.True(t, condition)
go-cmp:
if diff := cmp.Diff(want, got); diff != "" {
t.Errorf("Mismatch (-want +got):\n%s", diff)
}
Summary
is focuses on simplicity and ease of use, making it ideal for straightforward testing scenarios. It provides a concise API that's quick to learn and implement.
go-cmp offers more powerful comparison capabilities, especially for complex data structures and custom types. It's well-suited for projects with intricate testing requirements but may be overkill for simpler use cases.
Choose is for rapid development and simple tests, or go-cmp for more advanced comparison needs and long-term maintainability in larger projects.
Go testing in the browser. Integrates with `go test`. Write behavioral tests in Go.
Pros of goconvey
- Provides a web UI for real-time test results and coverage reports
- Offers a more extensive set of assertion functions
- Supports automatic test running on file changes
Cons of goconvey
- Steeper learning curve due to more complex API
- Requires additional setup and configuration
- May be considered overkill for smaller projects
Code Comparison
is:
is.Equal(t, got, want)
is.True(t, condition)
is.NoErr(t, err)
goconvey:
So(got, ShouldEqual, want)
So(condition, ShouldBeTrue)
So(err, ShouldBeNil)
Summary
is is a lightweight and straightforward testing package with a simple API, making it easy to learn and use for basic testing needs. It focuses on providing a clean and readable syntax for common assertions.
goconvey offers a more feature-rich testing environment with its web UI, extensive assertion functions, and automatic test running capabilities. It's well-suited for larger projects that require more comprehensive testing tools and real-time feedback.
The choice between the two depends on the project's size, complexity, and specific testing requirements. is may be preferable for smaller projects or those seeking simplicity, while goconvey could be advantageous for larger, more complex applications that benefit from its additional features and visual feedback.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
is
Professional lightweight testing mini-framework for Go.
- Easy to write and read
- Beautifully simple API with everything you need:
is.Equal
,is.True
,is.NoErr
, andis.Fail
- Use comments to add descriptions (which show up when tests fail)
Failures are very easy to read:
Usage
The following code shows a range of useful ways you can use the helper methods:
func Test(t *testing.T) {
is := is.New(t)
signedin, err := isSignedIn(ctx)
is.NoErr(err) // isSignedIn error
is.Equal(signedin, true) // must be signed in
body := readBody(r)
is.True(strings.Contains(body, "Hi there"))
}
Color
To turn off the colors, run go test
with the -nocolor
flag,
or with the env var NO_COLOR
(with any value).
go test -nocolor
NO_COLOR=1 go test
Top Related Projects
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot