import ( "testing" . "gopkg.in/check.v1" ) func TestFibonacci(t *testing.T) { checker := &Checker{Checker: &checkers.DeepEqual{}} Checkers = append(Checkers, checker) r := RunSpecs(t, "Fibonacci Suite") if !r.Passed() { t.Errorf("Test failed") } } func SuiteFibonacci(c *C) { c.Assert(Fibonacci(1), checker.Equals, 0) c.Assert(Fibonacci(2), checker.Equals, 1) c.Assert(Fibonacci(3), checker.Equals, 1) c.Assert(Fibonacci(4), checker.Equals, 2) c.Assert(Fibonacci(5), checker.Equals, 3) } func Fibonacci(n int) int { if n <= 1 { return 0 } else if n == 2 { return 1 } else { return Fibonacci(n-1) + Fibonacci(n-2) } }
import ( "testing" . "gopkg.in/check.v1" ) func TestPerson(t *testing.T) { tester := &TestPerson{} Suite(&testers{tester}) } type TestPerson struct{} func (t *TestPerson) TestName(c *C) { p := Person{Name: "Alice"} c.Assert(p.Name, checker.Equals, "Alice") } func (t *TestPerson) TestAge(c *C) { p := Person{Age: 25} c.Assert(p.Age, checker.Equals, 25) } type Person struct { Name string Age int }This code tests a simple `Person` struct using gocheck's `Checker`. The `Person` struct is defined as an ordinary Go struct, and the tests are defined within the `TestPerson` struct. The `Suite` function is used to group the tests together, and each test checks a field of the `Person` struct using the `Equals` checker.