• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

.travis.ymlH A D26-Aug-2018118

LICENSEH A D26-Aug-20181.1 KiB

README.mdH A D26-Aug-20181.6 KiB

go.modH A D26-Aug-201849

testing.goH A D26-Aug-20182.1 KiB

testing_go19.goH A D26-Aug-20182.3 KiB

testing_test.goH A D26-Aug-2018245

README.md

1# go-testing-interface
2
3go-testing-interface is a Go library that exports an interface that
4`*testing.T` implements as well as a runtime version you can use in its
5place.
6
7The purpose of this library is so that you can export test helpers as a
8public API without depending on the "testing" package, since you can't
9create a `*testing.T` struct manually. This lets you, for example, use the
10public testing APIs to generate mock data at runtime, rather than just at
11test time.
12
13## Usage & Example
14
15For usage and examples see the [Godoc](http://godoc.org/github.com/mitchellh/go-testing-interface).
16
17Given a test helper written using `go-testing-interface` like this:
18
19    import "github.com/mitchellh/go-testing-interface"
20
21    func TestHelper(t testing.T) {
22        t.Fatal("I failed")
23    }
24
25You can call the test helper in a real test easily:
26
27    import "testing"
28
29    func TestThing(t *testing.T) {
30        TestHelper(t)
31    }
32
33You can also call the test helper at runtime if needed:
34
35    import "github.com/mitchellh/go-testing-interface"
36
37    func main() {
38        TestHelper(&testing.RuntimeT{})
39    }
40
41## Why?!
42
43**Why would I call a test helper that takes a *testing.T at runtime?**
44
45You probably shouldn't. The only use case I've seen (and I've had) for this
46is to implement a "dev mode" for a service where the test helpers are used
47to populate mock data, create a mock DB, perhaps run service dependencies
48in-memory, etc.
49
50Outside of a "dev mode", I've never seen a use case for this and I think
51there shouldn't be one since the point of the `testing.T` interface is that
52you can fail immediately.
53