...

Package tester

import "github.com/Diarkis/diarkis/test/tester"
Overview
Index

Overview ▾

Package tester ▷

Tester - Unit test tools

Aids you to build uint tests.

Example

package main

import (
  "github.com/Diarkis/diarkis/test/tester"
)

func main() {

  // create a unit test container
  tests := tester.NewTests("Your unit test label")

  tests.Define("Can run some actions", func(next func(error)) {

    // we run some actions here
    // by calling next(), we tell the unit test container to move to the next test
    // if you pass an error to next(), the test fails and unit test terminates immediately
    next(nil)

  })

  // tests.Run() will start the tests
  tests.Run(func(err error) {
    // we are done!
  })

}

func RunTests

func RunTests(list []*Tests)

RunTests executes multiple *Tests as a single continuous test.

func Wait

func Wait(flag bool)

Wait keeps the process running until the given flag becomes true

type Test

Test represents a unit test

type Test struct {
    // contains filtered or unexported fields
}

type Tests

Tests represents a set of unit tests

type Tests struct {
    // contains filtered or unexported fields
}

func NewTests

func NewTests(name string) *Tests

NewTests creates a new Tests instance

func (*Tests) Assert

func (ts *Tests) Assert(given interface{}, expected interface{})

Assert evaluates the two given values and if they are evaluated to be different values, the test fails immediately.

func (*Tests) AssertNotEqual

func (ts *Tests) AssertNotEqual(given interface{}, expected interface{})

AssertNotEqual evaluates the two given values and if they are evaluated to be the same values, the test fails immediately.

func (*Tests) Async

func (ts *Tests) Async(cb func())

Async executes a given callback function asynchronously.

You must use this function instead of goroutine in your tests.

func (*Tests) Count

func (ts *Tests) Count() int

Count returns the number of tests.

func (*Tests) DebugLogging

func (ts *Tests) DebugLogging(d ...interface{})

DebugLogging outputs debug logging during the tests if the test process is started with --debug parameter.

func (*Tests) Define

func (ts *Tests) Define(label string, logic func(callback func(err error)))

Define creates a unit test. If you pass an error to the callback, the unit test fails.

tests.Define("Can run some actions", func(next func(error)) {

  // we run some actions here
  // by calling next(), we tell the unit test container to move to the next test
  // if you pass an error to next(), the test fails and unit test terminates immediately
  next(nil)

})

func (*Tests) GetCurrentTest

func (ts *Tests) GetCurrentTest() *Test

GetCurrentTest returns the current test.

func (*Tests) OnEnd

func (ts *Tests) OnEnd(cb func())

OnEnd assigns a callback to be called at the end of all tests.

This is useful when you have to clean up such as database etc. after your tests

func (*Tests) Run

func (ts *Tests) Run(finished func(err error))

Run executes all unit tests in the order of the tests defined.

If a unit test fails, the entire Tests fail.