ftest

package module
v1.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 1, 2018 License: MIT Imports: 3 Imported by: 0

README

Build Status

About

  • ftest is a simple and easy to use go testing library with fluent design and exact failure messages.
  • fclient is a simple http testing client, based on ftest.

Documentation:

Installation

go get -u github.com/alexbyk/ftest

Usage

ftest

import (
  "testing"

  "github.com/alexbyk/ftest"
)

func TestFoo(t *testing.T) {
  ftest.New(t).Eq(2, 2).
    Contains("FooBarBaz", "Bar").
    PanicsSubstr(func() { panic("Foo") }, "Foo")
}

You can also use your own label to group your test:

ft := ftest.NewLabel(t, "MyLabel")

fclient

package app_test

import (
  "fmt"
  "net/http"
  "testing"

  "github.com/alexbyk/ftest/fclient"
)

type MyApp struct{}

func (app MyApp) ServeHTTP(w http.ResponseWriter, r *http.Request) {
  w.Write([]byte(`{"foo": "bar"}`))
}

func Test_hello(t *testing.T) {
  app := MyApp{}
  cl := fclient.New(t, app)

  cl.Get("/hello").CodeEq(200).
    BodyContains("bar").
    JSONEq(`{"foo":"bar"}`)

  // using a response directly
  res := cl.Get("/hello")
  fmt.Println(res.Body)
}

Copyright 2018, alexbyk.com

Documentation

Overview

Package ftest is a simple easy to use testing library. It prints only the exact location of failed test (without scary stack trace). It uses a fluent desing. It stops a test on the first failure

	ftest.New(t).Eq(2, 2).
		Contains("FooBarBaz", "Bar").
    PanicsSubstr(func() { panic("Foo") }, "Foo")

Also to make testing simpler, this package performs extra nil checks, so nil, non initialized slice and empty pointer - all will be considered equal (and that's what you are expecting)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Assertion

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

Assertion represents an assertion which holds current a *testing.T object

func New

func New(t test) *Assertion

New creates an Assertion instance with label "Assertion"

func NewLabel

func NewLabel(t test, label string) *Assertion

NewLabel creates an Assertion instance with a label

func (*Assertion) Contains

func (ass *Assertion) Contains(str, substr string) *Assertion

Contains checks if the first argument contains a second one

func (*Assertion) Containsf

func (ass *Assertion) Containsf(str, substr, format string, args ...interface{}) *Assertion

Containsf is like Contains but fails with given format and arguments

func (*Assertion) Eq

func (ass *Assertion) Eq(got, expected interface{}) *Assertion

Eq tests if 2 arguments are equal

func (*Assertion) Eqf

func (ass *Assertion) Eqf(got, expected interface{}, format string, args ...interface{}) *Assertion

Eqf is an f version of Eq

func (*Assertion) False

func (ass *Assertion) False(got bool) *Assertion

False tests if a given argument is false

func (*Assertion) Falsef

func (ass *Assertion) Falsef(got bool, format string, args ...interface{}) *Assertion

Falsef is an f version of False

func (*Assertion) Nil

func (ass *Assertion) Nil(got interface{}) *Assertion

Nil tests if a given argument is nil

func (*Assertion) Nilf

func (ass *Assertion) Nilf(got interface{}, format string, args ...interface{}) *Assertion

Nilf is an f vetsion of Nil

func (*Assertion) NotEq

func (ass *Assertion) NotEq(got, expected interface{}) *Assertion

NotEq tests if 2 arguments are equal

func (*Assertion) NotEqf

func (ass *Assertion) NotEqf(got, expected interface{}, format string, args ...interface{}) *Assertion

NotEqf is an f version of NotEq

func (*Assertion) NotNil

func (ass *Assertion) NotNil(got interface{}) *Assertion

NotNil tests if a given argument isn't nil

func (*Assertion) NotNilf

func (ass *Assertion) NotNilf(got interface{}, format string, args ...interface{}) *Assertion

NotNilf is an f vetsion of NotNil

func (*Assertion) PanicsSubstr

func (ass *Assertion) PanicsSubstr(fn func(), substr string) (ret *Assertion)

PanicsSubstr tests if a given function causes and panic and an error contains given substring. You can pass an empty string("") if the error doesn't matter

func (*Assertion) True

func (ass *Assertion) True(got bool) *Assertion

True tests if a given argument is true

func (*Assertion) Truef

func (ass *Assertion) Truef(got bool, format string, args ...interface{}) *Assertion

Truef is an f version of True

Directories

Path Synopsis
Package fclient provides a testing client for http handlers.
Package fclient provides a testing client for http handlers.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL