a very minimal, highly simplified testing framework.
  • Go 93.1%
  • Makefile 6.9%
Find a file
2025-12-15 18:55:19 +01:00
assertions.go isNil() required to test nil interface values 2025-02-24 14:41:27 +01:00
assertions_test.go Fail & Fatal distinction made 2024-03-07 05:04:01 +01:00
doc.go header rows added to tables 2024-02-09 18:11:27 +01:00
example_table_test.go extend ruler regexp to recognise alignment and sorting characters (regex is not a good solution!) 2025-12-15 18:55:19 +01:00
fieldmap.go generic FieldByNameFunc function added 2025-02-22 22:01:52 +01:00
fieldmap_test.go FieldByNameFunc added 2025-01-29 03:24:33 +01:00
go.mod migrated to codeberg address for publication 2023-01-22 14:23:31 +01:00
is.go Fail & Fatal distinction made 2024-03-07 05:04:01 +01:00
LICENSE update license and ReadMe 2021-12-13 13:50:13 +01:00
Makefile header rows added to tables 2024-02-09 18:11:27 +01:00
ReadMe.md readme update 2025-01-29 03:33:04 +01:00
reporter.go message prefix added 2024-03-04 13:52:19 +01:00
reporter_test.go message prefix added 2024-03-04 13:52:19 +01:00
table.go extend ruler regexp to recognise alignment and sorting characters (regex is not a good solution!) 2025-12-15 18:55:19 +01:00
table_test.go extend ruler regexp to recognise alignment and sorting characters (regex is not a good solution!) 2025-12-15 18:55:19 +01:00

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 only
    • go 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

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 testing package 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 is was created
    • differences
      • uses a per-test instance to simplify the interface

2021, Stephen Riehm, japh-codeberg@opensauce.de