Skip to content

TestaRossa is a simple utility on top of Go's standard testing library that prints the full/path/to/the/source/file/of/the/unit_test.go:line of a failed assertion

License

Notifications You must be signed in to change notification settings

microbus-io/testarossa

Repository files navigation

Testa Rossa

TestaRossa is a simple utility on top of Go's standard testing library that prints the full/path/to/the/source/file/of/the/unit_test.go:line of a failed assertion, which in VSCode is a clickable link. Unlike t.Log, output is printed using fmt.Printf during the execution of the test rather than at its conclusion.

TestaRossa supports a functional pattern:

func TestMe(t *testing.T) {
    testarossa.Equal(t, 1, 0, "You are not the %d", 1)
    
    err := errors.New("This is bad")
    testarossa.NoError(t, err)

    html := `<html><body><div class="banner">Hello, <b>World</b>!</div></body></html>`
    testarossa.HTMLMatch(t, html, "DIV.banner", "^World$")

    droids := 1234
    testarossa.FailIf(t, droids != 0, "These are not the droids you are looking for")
    
    err = errors.New("This is really bad")
    testarossa.FatalIfError(t, err)
}

as well as a more object-oriented pattern:

func TestMe(t *testing.T) {
    tt := testarossa.For(t)

    tt.Equal(1, 0, "You are not the %d", 1)
    
    err := errors.New("This is bad")
    tt.NoError(err)
    
    result, err := doSomething(param)
    tt.Expect(err, nil, result, 1234)

    html := `<html><body><div class="banner">Hello, <b>World</b>!</div></body></html>`
    tt.HTMLMatch(html, "DIV.banner", "^World$")
}

Example test output:

--- FAIL: TestMe
    /my_projects/github.com/microbus-io/testarossa/my_test.go:10
    Expected '1', actual '0'
    You are not the 1
--- FAIL: TestMe
    /my_projects/github.com/microbus-io/testarossa/my_test.go:12
    Expected no error
    This is bad
--- FAIL: TestMe (0.00s)
FAIL
FAIL	github.com/microbus-io/testarossa	0.173s
FAIL

TestaRossa is licensed by Microbus LLC under the Apache License 2.0.

About

TestaRossa is a simple utility on top of Go's standard testing library that prints the full/path/to/the/source/file/of/the/unit_test.go:line of a failed assertion

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages