README.md
1ut (utiltest)
2=============
3
4Collection of small functions to shorten Go test cases.
5
6Requires Go 1.2 due to the use of `testing.TB`. If needed, replace with
7`*testing.T` at the cost of not being usable in benchmarks.
8
9[![GoDoc](https://godoc.org/github.com/maruel/ut?status.svg)](https://godoc.org/github.com/maruel/ut)
10[![Build Status](https://travis-ci.org/maruel/ut.svg?branch=master)](https://travis-ci.org/maruel/ut)
11[![Coverage Status](https://img.shields.io/coveralls/maruel/ut.svg)](https://coveralls.io/r/maruel/ut?branch=master)
12
13
14Examples
15--------
16
17 package foo
18
19 import (
20 "github.com/maruel/ut"
21 "log"
22 "strconv"
23 "testing"
24 )
25
26 func TestItoa(t *testing.T) {
27 ut.AssertEqual(t, "42", strconv.Itoa(42))
28 }
29
30 func TestItoaDataListDriven(t *testing.T) {
31 data := []struct {
32 in int
33 expected string
34 }{
35 {9, "9"},
36 {11, "11"},
37 }
38 for i, item := range data {
39 ut.AssertEqualIndex(t, i, item.expected, strconv.Itoa(item.in))
40 }
41 }
42
43 func TestWithLog(t *testing.T) {
44 out := ut.NewWriter(t)
45 defer out.Close()
46
47 logger := log.New(out, "Foo:", 0)
48
49 // These will be included in the test output only if the test case fails.
50 logger.Printf("Q: What is the answer to life the universe and everything?")
51 logger.Printf("A: %d", 42)
52 }
53