Documentation
¶
Overview ¶
Package test contains helper functions to remove common boilerplate to make testing easier.
The ExpectEquality() is the most basic and probably the most useful function. It compares like-typed variables for equality and returns true if they match.
The ExpectFailure() and ExpectSuccess() functions test for failure and success. These two functions work with bool or error and special handling for nil.
The Writer type meanwhile, implements the io.Writer interface and should be used to capture output. The Writer.Compare() function can then be used to test for equality.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExpectEquality ¶ added in v0.25.0
func ExpectEquality[T comparable](t *testing.T, value T, expectedValue T)
ExpectEquality is used to test equality between one value and another
func ExpectFailure ¶ added in v0.25.0
ExpectFailure tests argument v for a failure condition suitable for it's type. Types bool and error are treated thus:
bool == false error != nil
If type is nil then the test will fail
func ExpectInequality ¶ added in v0.25.0
func ExpectInequality[T comparable](t *testing.T, value T, expectedValue T)
ExpectInequality is used to test inequality between one value and another. In other words, the test does not want to succeed if the values are equal
func ExpectSuccess ¶ added in v0.25.0
ExpectSuccess tests argument v for a success condition suitable for it's type. Types bool and error are treated thus:
bool == true error == nil
If type is nil then the test will succeed
Types ¶
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
Writer is an implementation of the io.Writer interface. It should be used to capture output and to compare with predefined strings.