pass

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2024 License: MIT Imports: 4 Imported by: 0

README

github.com/breml/pass

Test Status Go Report Card License

Package pass allows you to early end Go unit tests successfully, which also works from called functions outside of the test function.

Reasoning

While the testing package provides several methods on *testing.T to fail a test early, there is no method provided to end a test early successfully. Obviously, you can use return to end a test early, but this only works from inside of the test function and it strictly requires the use of conditions to verify the test result.

Me personally, I aim to keep my test functions as simple as possible and I try to avoid conditions in test functions as much as possible. Sometimes, in more complext test scenarios find myself in a situation, where it is not possible to continue a test case, because I expect a function to fail (those the test is successful) but it is not safe to continue the test, since the necessary pre- conditions for the subsequent logic are not met. In such a case, I would like to end the test case early, but still mark it as successful.

This is where this package comes into play. It allows you to end a test case early, but still mark it as successful.

Distinction to (*testing.T).SkipNow

The testing package provides the (*testing.T).SkipNow function, which allows you to skip the current test case. The effect of the two functions is very similar. The only difference is, that (*testing.T).SkipNow will print a message indicating that the test was skipped (optionally with a reason, if (*testing.T).Skip or (*testing.T).Skipf was used) in the following form:

--- SKIP: TestSkipNow (0.00s)

The pass package does mark the test as successfully completed and those the message on the console will have the follwing form:

--- PASS: TestNow (0.00s)

Example

See example_test.go for a descriptive example.

Installation

go get github.com/breml/pass

Author

Copyright 2024 by Lucas Bremgartner (breml)

License

MIT License

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Now

func Now(t *testing.T)

Now marks the test as being successful (PASS:) and stops its execution by calling runtime.Goexit. If a test fails (see testing.Error, testing.Errorf, testing.Fail) and is then ended using this function, it is still considered to have failed. Execution will continue at the next test. Now must be called from the goroutine running the test, not from other goroutines created during the test. Calling Now does not stop those other goroutines.

Types

This section is empty.

Jump to

Keyboard shortcuts

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