Ginkgo Testing Framework

Qualified uses the Ginkgo BDD testing framework with Gomega matcher library.

Test Structure

package challenge

func Add(a, b int) int {
  return a + b
}
package challenge_test

import (
  . "github.com/onsi/ginkgo"
  . "github.com/onsi/gomega"
  . "codewarrior/challenge"
)

var _ = Describe("Add", func() {
  It("should add integers", func() {
    Expect(Add(1, 1)).To(Equal(2))
  })
})

Note

Package name (challenge in above example) can be arbitrary ([a-z][a-z\d]*).

The import path is codewarrior/{package name}.

Following code is automatically generated by lib/runners/go.js:

package challenge_test

import (
  . "github.com/onsi/ginkgo"
  . "github.com/onsi/gomega"
  "testing"
  "codewars/reporter"
)

func TestChallenge(t *testing.T) {
  RegisterFailHandler(Fail)
  RunSpecsWithCustomReporters(t, "Challenge Test", []Reporter{reporter.New()})
}

Preloaded code is just another file ('setup.go') in the package.

package challenge

const foo = "bar" // package scoped

type Point struct{ x, y float64 } // exported

Matchers

Expect(ACTUAL).To(M)
Expect(ACTUAL).ToNot(M)
Expect(ACTUAL).NotTo(M)