Skip to content

ppapapetrou76/go-testing

Repository files navigation

Codacy Badge Fluent Go Testing Go Report Card GoDoc Quality Gate Status codecov

go-testing

GoLang fluent API for test assertions

Quick Start

import (
  "testing"

  "github.com/ppapapetrou76/go-testing"
)

type assertedStruct struct {
	boolField   bool
	stringField string
	intField    int
	sliceField  []string
}


func TestAssertedStruct(t *testing.T) {
	assertedStruct := assertedStruct{}
	assertedStruct.boolField = true
	assertedStruct.stringField = "I am a very proud asserted string"
	assertedStruct.intField = -10
	assertedStruct.sliceField = []string{"elem1", "elem2"}

	ft := assert.NewFluentT(t)
	ft.AssertThatBool(assertedStruct.boolField).
		IsTrue().
		IsEqualTo(true).
		IsNotEqualTo(false)

	ft.AssertThatString(assertedStruct.stringField).
		IsEqualTo("I am a very proud asserted string").
		IsNotEmpty().
		IsNotEqualTo("I'm very proud too")

	ft.AssertThatInt(assertedStruct.intField).
		IsEqualTo(-10).
		IsNotEqualTo(10).
		IsGreaterThan(-20).
		IsGreaterThanOrEqualTo(-20).
		IsGreaterThanOrEqualTo(-10).
		IsLessThan(0).
		IsLessThanOrEqualTo(0).
		IsLessThanOrEqualTo(-10)

	ft.AssertThatSlice(assertedStruct.sliceField).
		HasSize(2).
		Contains("elem1").
		ContainsOnly([]string{"elem1", "elem2"}).
		DoesNotContain("elem3")
}

Supported

For the following types basic assertions are supported

  • int
  • uint
  • bool
  • string
  • slice
  • structure
  • map

To be implemented soon

  • time.Duration (basic assertions)
  • time.Time (basic assertions)
  • moar string assertions
    • ContainsOnlyWhitespaces
    • ContainsWhitespaces
    • DoesNotContainAnyWhitespaces
    • DoesNotContainOnlyWhitespaces
    • DoesNotEndWith
    • DoesNotStartWith
    • EndsWith
    • HasLineCount
    • HasSameSizeAs
    • HasSizeBetween
    • HasSizeGreaterThan
    • HasSizeGreaterThanOrEqualTo
    • HasSizeLessThan
    • HasSizeLessThanOrEqualTo
    • IsEqualToIgnoringCase
    • IsEqualToIgnoringNewLines
    • IsEqualToIgnoringWhitespace
    • IsLowerCase
    • IsNotEqualToIgnoringCase
    • IsNotEqualToIgnoringWhitespace
    • IsSubstringOf
    • IsUpperCase