Documentation
¶
Overview ¶
Package contracts provides members to register and test Mock objects. It is intended to be used in concert with "*testing.T" functions, and the "go test" command, which automates execution of any function of the form:
"func TestXxx(*testing.T)" functions.
Index ¶
- func Fluent[T any](t *testing.T) fluent.IFluent[T, IComparable[T]]
- type Additional
- type AdditionalWith
- type Comparable
- func (c *Comparable[T]) BeOfType(typeName reflect.Type) f.IAdditional[T, IComparable[T]]
- func (c *Comparable[T]) HaveAllFieldsWithTag(tagName string) f.IAdditional[T, IComparable[T]]
- func (c *Comparable[T]) HaveAllOfMembers(membersNames []string) f.IAdditional[T, IComparable[T]]
- func (c *Comparable[T]) HaveAnyOfMembers(membersNames []string) f.IAdditional[T, IComparable[T]]
- func (c *Comparable[T]) HaveField(fieldName string) IAdditionalWith[T]
- func (c *Comparable[T]) HaveFieldWithTag(fieldName string, tagName string) f.IAdditional[T, IComparable[T]]
- func (c *Comparable[T]) HaveMember(memberName string) f.IAdditional[T, IComparable[T]]
- func (c *Comparable[T]) HaveMethod(methodName string) f.IAdditional[T, IComparable[T]]
- func (c *Comparable[T]) NotBeOfType(typeName reflect.Type) f.IAdditional[T, IComparable[T]]
- type FluentT
- type IAdditionalWith
- type IComparable
- type Subject
- type Testable
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Additional ¶
type Additional[T any] struct { *Comparable[T] }
Additional[T any] is a type returned by some easy-to-use testing methods, providing basic additive test chaining with "And()".
func (*Additional[T]) And ¶
func (s *Additional[T]) And() IComparable[T]
And extends the testing operation againts the Mock subject, returning an "*Comparable[T]" object which provides a set of easy-to-use methods to test the subject in an additive maner.
The "And()" method works as an additive connector between test methods from "IComparable[T any]", allowing execution of chained testing methods.
package tdd import "testing" import "github.com/sciensoft/fluenttests/fluent/contracts" func TestFluentContractsShouldHaveAllOfMembers(t *testing.T) { // Arrange fluent := contracts.Fluent[any](t) // ... code hiden for brevity // Assert fluent.It(obj). Should().BeOfType(objType). And().HaveField("A").OfType(fieldType).WithValue(1) }
type AdditionalWith ¶ added in v0.0.3
type AdditionalWith[T any] struct { *Additional[T] // contains filtered or unexported fields }
AdditionalWith[T any] is a type returned by some easy-to-use testing methods, providing some extra additive test chaining with "OfType()", and "WithValue()".
func (*AdditionalWith[T]) OfType ¶ added in v0.0.3
func (a *AdditionalWith[T]) OfType(ctype reflect.Type) IAdditionalWith[T]
OfType is an extra method used to support assertion by type and made available through some easy-to-use testing methods.
func (*AdditionalWith[T]) WithValue ¶ added in v0.0.3
func (a *AdditionalWith[T]) WithValue(value any) IAdditionalWith[T]
WithValue is an extra method used to support assertion by a specific value and made available through some easy-to-use testing methods.
type Comparable ¶
Comparable[T any] is a type returned by calling "fluentObj.It(myMockObj).Should()", encapsulating a "*Testable[T]" object for further testing, and providing all the contracts package's easy-to-use set of methods with signatures declared at the "contracts.IComparable[any]" interface.
func (*Comparable[T]) BeOfType ¶
func (c *Comparable[T]) BeOfType(typeName reflect.Type) f.IAdditional[T, IComparable[T]]
BeOfType asserts a Mock objects as being of the provided type "typeName reflect.Type" argument.
func (*Comparable[T]) HaveAllFieldsWithTag ¶
func (c *Comparable[T]) HaveAllFieldsWithTag(tagName string) f.IAdditional[T, IComparable[T]]
HaveAllFieldsWithTag asserts a Mock objects as having a all its fields with the tag name as per "tagName string" argument.
func (*Comparable[T]) HaveAllOfMembers ¶
func (c *Comparable[T]) HaveAllOfMembers(membersNames []string) f.IAdditional[T, IComparable[T]]
HaveAllOfMembers asserts a Mock objects as having all of its named members (methods & fields) as per "membersNames []string" argument.
func (*Comparable[T]) HaveAnyOfMembers ¶
func (c *Comparable[T]) HaveAnyOfMembers(membersNames []string) f.IAdditional[T, IComparable[T]]
HaveAnyOfMembers asserts a Mock objects as having any of its named members (methods & fields) as per "membersNames []string" argument.
func (*Comparable[T]) HaveField ¶
func (c *Comparable[T]) HaveField(fieldName string) IAdditionalWith[T]
HaveField asserts a Mock objects as having a field named as per "fieldName string" argument.
func (*Comparable[T]) HaveFieldWithTag ¶
func (c *Comparable[T]) HaveFieldWithTag(fieldName string, tagName string) f.IAdditional[T, IComparable[T]]
HaveFieldWithTag asserts a Mock objects as having a field named as per "fieldName string" argument and with tag name as per "tagName string" argument.
func (*Comparable[T]) HaveMember ¶
func (c *Comparable[T]) HaveMember(memberName string) f.IAdditional[T, IComparable[T]]
HaveMember asserts a Mock objects as having a member, either a method or field, named as per "memberName string" argument.
func (*Comparable[T]) HaveMethod ¶
func (c *Comparable[T]) HaveMethod(methodName string) f.IAdditional[T, IComparable[T]]
HaveMethod asserts a Mock objects as having a method named as per "methodName string" argument.
func (*Comparable[T]) NotBeOfType ¶
func (c *Comparable[T]) NotBeOfType(typeName reflect.Type) f.IAdditional[T, IComparable[T]]
NotBeOfType asserts a Mock objects as NOT being of the provided type "typeName reflect.Type" argument.
type FluentT ¶
type FluentT[T any] struct { // contains filtered or unexported fields }
FluentT[T any] is a type returned by calling "contracts.Fluent[any](t)" for enabling easy-to-use testing methods.
It carries the "*testing.T" object to be further used in the methods chain.
type IAdditionalWith ¶ added in v0.0.3
type IAdditionalWith[T any] interface { fluent.IAdditional[T, IComparable[T]] OfType(ctype reflect.Type) IAdditionalWith[T] WithValue(value any) IAdditionalWith[T] }
IAdditionalWith[T any] interface for the contracts package.
type IComparable ¶
type IComparable[T any] interface { fluent.IComparable[T] BeOfType(typeName reflect.Type) fluent.IAdditional[T, IComparable[T]] NotBeOfType(typeName reflect.Type) fluent.IAdditional[T, IComparable[T]] HaveMember(memberName string) fluent.IAdditional[T, IComparable[T]] HaveField(fieldName string) IAdditionalWith[T] HaveFieldWithTag(fieldName string, tagName string) fluent.IAdditional[T, IComparable[T]] HaveAllFieldsWithTag(tagName string) fluent.IAdditional[T, IComparable[T]] HaveMethod(methodName string) fluent.IAdditional[T, IComparable[T]] HaveAnyOfMembers(membersNames []string) fluent.IAdditional[T, IComparable[T]] HaveAllOfMembers(membersNames []string) fluent.IAdditional[T, IComparable[T]] }
IComparable[T any] interface for the contracts package. Following the Fluent-Interface design pattern to provide chained testing methods.
type Subject ¶
Subject[T any] is a type returned by calling "fluentObj.It(myMockObj)" used to encapsulate the "*testing.T" object and testable subject.
func (*Subject[T]) Should ¶
func (s *Subject[T]) Should() IComparable[T]
Should starts the testing operations agains the Mock subject, returning an "*Comparable[T]" object which provides a set of easy-to-use methods to test the subject in an additive maner.
type Testable ¶
type Testable[T any] struct { // contains filtered or unexported fields }
Testable[T any] is a type that holds the "*testing.T" object and the underline Mock object, supporting further testing using the chain of easy-to-use methods. It's used by the "Subject[T any]" and "Comparable[T any]" types.