テストの時だけメソッドをはやす

main.go

package main

import "fmt"

type Foo struct {
    I int
    J int
}

func (foo *Foo) Sum() int {
    return foo.I + foo.J
}

func main() {
    foo := &Foo{1, 2}
    fmt.Println(foo.Sum())
}

helper_test.go

package main

import (
    "fmt"
)

func (foo *Foo) Dump() string {
    return fmt.Sprintf("%+v", foo)
}

main_test.go

package main_test

// ↓ではメソッドをはやせない
// type Foo = main.Foo
// type Foo main.Foo

import (
    main "hello"
    "testing"

    "github.com/stretchr/testify/assert"
)

func TestHello(t *testing.T) {
    assert := assert.New(t)
    foo := &main.Foo{1, 2}
    assert.Equal(3, foo.Sum())
    t.Log(foo.Dump())
}