- Go 93.1%
- Makefile 6.9%
| assertions.go | ||
| assertions_test.go | ||
| doc.go | ||
| example_table_test.go | ||
| fieldmap.go | ||
| fieldmap_test.go | ||
| go.mod | ||
| is.go | ||
| LICENSE | ||
| Makefile | ||
| ReadMe.md | ||
| reporter.go | ||
| reporter_test.go | ||
| table.go | ||
| table_test.go | ||
is
A very minimal, highly simplified testing framework for golang 1.18 and above.
Features
- 1-line test descriptions (no need for
if/else) - positive as well as negative results ("
passed ...")go test ./...=> shows failed tests onlygo test -v ./...=> show passed and failed tests
- consistent output formatting
- easier to read and comprehend test results
- errors produce 3 lines:
- your message
- the received value
- the expected value
- errors produce 3 lines:
- easier to read and comprehend test results
Usage
import (
"testing"
"codeberg.org/japh/is"
)
func TestGreetings( t *testing.T ) {
is := is.New(t)
a := "hello"
is.Equal(a, "hello", "a pleasant greeting")
is.NotEqual(a, "hi", "a pleasant greeting")
b := &struct{
name string
pet *Pet
}{
name:"Jenny",
}
is.NotNil(b, "be should not be nil")
is.Equal(b.name, "Jenny", "is the name 'Jenny'")
is.Nil(b.pet, "Jenny does not have any pets :-(")
}
Support For Data Driven Test Cases
The is package also provides a simple way to provide tables of test data.
e.g.
func TestGreetingCategorizer( t *testing.T ) {
is := is.New(t)
testCases := is.TableFromString(`
| greeting | category | description |
| ------------ | -------- | ------------------------------------------- |
| Good Evening | formal | greeting for evenings, e.g. at a restaurant |
| Hello | informal | typical greeting |
| Hi | casual | only among friends |
| Salutations | archaic | where did you hear this? |
`)
// value is a function which returns the string value of the column with a
// given name.
value := testCases.FieldByNameFunc()
for _, tc := testCases.DataRows() {
givenGreeting := value(tc,"greeting")
wantCategory := value(tc,"category")
description := value(tc,"desc")
gotCategory := categoryOfWord(greeting)
is.Equal(gotCategory, wantCategory, description)
}
}
Background
There are plenty of feature-rich testing frameworks for go, incuding go's own
testing package, however, I haven't found any that fit my testing philosophy:
-
go's
testingpackage assumes that all tests ran and only reports errors.In my experience, saying "nothing broke" is not the same as "everyting worked", so I want positive feedback as well.
-
other packages, such as testify, go in the other direction, providing feature-rich API's with everything you could possible want, at the expense of additional complexity.
... but I just want to check simple yes/no expectations, with equally simple, readable output. And this is it :-)
- and then I saw Mat Ryer's
is| github- which was a bit simpler
- but a bit too minimalistic
- so this version of
iswas created - differences
- uses a per-test instance to simplify the interface
Copyright
2021, Stephen Riehm, japh-codeberg@opensauce.de