td.T

Constructing *td.T

import (
  "testing"

  "github.com/maxatome/go-testdeep/td"
)

func TestMyFunc(tt *testing.T) {
  t := td.NewT(tt)
  t.Cmp(MyFunc(), 12)
}

Configuring *td.T

func TestMyFunc(tt *testing.T) {
  t := td.NewT(tt).UseEqual().RootName("RECORD")
  ...
}

Main methods of *td.T

import (
  "testing"

  "github.com/maxatome/go-testdeep/td"
)

func TestMyFunc(tt *testing.T) {
  t := td.NewT(tt).UseEqual()

  // Compares MyFunc() result against a fixed value
  t.Cmp(MyFunc(), 128, "MyFunc() result is 128")

  // Compares MyFunc() result using the Between Testdeep operator
  t.Cmp(MyFunc(), td.Between(100, 199),
    "MyFunc() result is between 100 and 199")
}

CmpDeeply() method is now replaced by Cmp(), but it is still available for backward compatibility purpose.

Anchoring methods of *td.T

Shortcut methods of *td.T

import (
  "testing"

  "github.com/maxatome/go-testdeep/td"
)

func TestMyFunc(tt *testing.T) {
  t := td.NewT(tt).UseEqual()
  t.Between(MyFunc(), 100, 199, td.BoundsInIn,
    "MyFunc() result is between 100 and 199")
}

For each of these methods, it is always a shortcut on T.Cmp() and the correponding Testdeep operator:

T.HasPrefix(got, expected, …) ⇒ T.Cmp(t, got, HasPrefix(expected), …)
  ^-------^                                   ^-------^
      +-------------------------------------------+

Excluding Lax operator for which the shortcut method stays CmpLax.

Each shortcut method is described in the corresponding operator page. See operators list.