Documentation
¶
Overview ¶
Package assert provides a small collection of test assertion helpers built on top of the standard testing package.
The functions in this package are designed to be used directly inside Go test functions. Each helper accepts a *testing.T, calls t.Helper so that failure messages point to the call site, and reports errors via t.Errorf rather than t.Fatalf, allowing a test to record multiple failures in a single run.
Available Assertions ¶
AssertEqual(t, got, want) // deep equality via reflect.DeepEqual AssertNil(t, value) // value must be nil AssertNotNil(t, value) // value must not be nil AssertTrue(t, condition) // boolean must be true AssertFalse(t, condition) // boolean must be false
Usage ¶
func TestAdd(t *testing.T) {
result := Add(2, 3)
assert.AssertEqual(t, result, 5)
}
assert is used throughout the replify test suite as a lightweight alternative to external assertion libraries, keeping test dependencies minimal while still providing clear failure messages.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertEqual ¶
AssertEqual compares two objects for equality and reports a test failure if they are not equal.
This function uses the `reflect.DeepEqual` function to check if `object1` and `object2` are deeply equal. If they are not, the function marks the test as failed and reports an error message.
Parameters:
- `t`: The testing instance (from `*testing.T`) used to report failures.
- `object1`: The first object to compare.
- `object2`: The second object to compare.
Example:
AssertEqual(t, actualValue, expectedValue)
func AssertFalse ¶
AssertFalse checks if the given boolean is false and reports a test failure if it is not.
This function internally calls `AssertEqual` to compare the boolean value `b` with `false`. If the comparison fails, it marks the test as failed and reports an error.
Parameters:
- `t`: The testing instance (from `*testing.T`) used to report failures.
- `b`: The boolean value to check.
Example:
AssertFalse(t, hasError)
func AssertNil ¶
AssertNil checks if the given object is nil and reports a test failure if it is not.
This function uses the `IsNil` helper function to determine if the object is nil. If the object is not nil, it marks the test as failed and reports an error.
Parameters:
- `t`: The testing instance (from `*testing.T`) used to report failures.
- `object`: The object to check for nil.
Example:
AssertNil(t, err)
func AssertNotNil ¶
AssertNotNil checks if the given object is not nil and reports a test failure if it is nil.
This function uses the `IsNil` helper function to determine if the object is nil. If the object is nil, it marks the test as failed and reports an error.
Parameters:
- `t`: The testing instance (from `*testing.T`) used to report failures.
- `object`: The object to check for non-nil.
Example:
AssertNotNil(t, result)
func AssertTrue ¶
AssertTrue checks if the given boolean is true and reports a test failure if it is not.
This function internally calls `AssertEqual` to compare the boolean value `b` with `true`. If the comparison fails, it marks the test as failed and reports an error.
Parameters:
- `t`: The testing instance (from `*testing.T`) used to report failures.
- `b`: The boolean value to check.
Example:
AssertTrue(t, isValid)
Types ¶
This section is empty.