Testza
Full-featured test framework for Go! Assertions, fuzzing, input testing, output capturing, and much more! 🍕
Install / Use
/learn @MarvinJWendt/TestzaREADME
<p align="center"> <strong><a href="https://github.com/MarvinJWendt/testza#-installation">Get The Module</a></strong> | <strong><a href="https://github.com/MarvinJWendt/testza#-documentation" target="_blank">Documentation</a></strong> | <strong><a href="https://github.com/atomicgo/atomicgo/blob/main/CONTRIBUTING.md" target="_blank">Contributing</a></strong> | <strong><a href="https://github.com/atomicgo/atomicgo/blob/main/CODE_OF_CONDUCT.md" target="_blank">Code of Conduct</a></strong> </p>
<img align="right" height="400" alt="Screenshot of an example test message" src="https://user-images.githubusercontent.com/31022056/161153895-e772bc61-b751-407f-b526-8f6a66d8f8d5.png" /> <br/> <p align="center"> <a href="https://discord.gg/vE2dNkfAmF"> <img width="300" src="https://user-images.githubusercontent.com/31022056/158916278-4504b838-7ecb-4ab9-a900-7dc002aade78.png" alt="Join us on Discord!" /> <br/> <b>Join us on Discord for support, discussions, updates and general talk!</b> </a> </p>
📦 Installation
# Execute this command inside your project
go get github.com/MarvinJWendt/testza
<br/>
<br/>
📝 Description
Testza is a full-featured testing framework for Go.
It integrates with the default test runner, so you can use it with the standard go test tool.
Testza contains easy to use methods, like assertions, output capturing, fuzzing, and much more.
The main goal of testza is to provide an easy and fun experience writing tests and providing a nice, user-friendly output. Even developers who never used testza, will get into it quickly.
⭐ Features
| Feature | Description | |--------------------|------------------------------------------------------------------------------------------------------------------------------------------------------| | Assertions | Assertions allow you to quickly check objects for expected values. | | Fuzzing | Fuzzing allows you to check functions against sets of generated input parameters.<br/>A couple lines of test code can run thousands of sanity tests. | | Output Capture | Capture and validate output written to the terminal.<br/>Perfect for CLI tools. | | Snapshots | Snapshot objects between test runs, to ensure a consistent behaviour. | | Clean Output | Clean and colorful output provides you the needed details in an easy-to-understand format. | | System Information | Testza prints information about the system on startup.<br/> You can quickly figure out what's wrong, when a user submits an issue. | | Well Documented | Every function of testza is well documented and contains an example to make usage super easy. | | Customizable | Testza features customizable settings, if you want to change something. | | Test flags | You can configure testza via flags too!<br/>That makes it super simple to change test runs, or output, without touching code! |
🚀 Getting Started
See the examples below for a quick introduction!
// --- Some Examples ---
// - Some assertions -
testza.AssertTrue(t, true) // -> Pass
testza.AssertNoError(t, err) // -> Pass
testza.AssertEqual(t, object, object) // -> Pass
// ...
// - Testing console output -
// Test the output of your CLI tool easily!
terminalOutput, _ := testza.CaptureStdout(func(w io.Writer) error {fmt.Println("Hello"); return nil})
testza.AssertEqual(t, terminalOutput, "Hello\n") // -> Pass
// - Fuzzing -
// Testing a function that accepts email addresses as a parameter:
// Testset of many different email addresses
emailAddresses := testza.FuzzStringEmailAddresses()
// Run a test for every string in the test set
testza.FuzzStringRunTests(t, emailAddresses, func(t *testing.T, index int, str string) {
user, domain, err := internal.ParseEmailAddress(str) // Use your function
testza.AssertNoError(t, err) // Assert that your function does not return an error
testza.AssertNotZero(t, user) // Assert that the user is returned
testza.AssertNotZero(t, domain) // Assert that the domain is returned
})
// And that's just a few examples of what you can do with Testza!
📚 Documentation
<!-- docs:start --> <table> <tr> <th>Module</th> <th>Methods</th> </tr><tr> <td><a href="https://github.com/MarvinJWendt/testza#Settings">Settings</a></td> <td> <details> <summary>Click to expand</summary> </td> </details> </tr> <tr> <td><a href="https://github.com/MarvinJWendt/testza#Assert">Assert</a></td> <td> <details> <summary>Click to expand</summary>- AssertCompletesIn
- AssertContains
- AssertDecreasing
- AssertDirEmpty
- AssertDirExists
- AssertDirNotEmpty
- AssertEqual
- AssertEqualValues
- AssertErrorIs
- AssertFalse
- AssertFileExists
- AssertGreater
- AssertGreaterOrEqual
- AssertImplements
- AssertInRange
- AssertIncreasing
- AssertKindOf
- AssertLen
- AssertLess
- AssertLessOrEqual
- AssertNil
- AssertNoDirExists
- AssertNoError
- AssertNoFileExists
- AssertNoSubset
- AssertNotCompletesIn
- AssertNotContains
- AssertNotEqual
- AssertNotEqualValues
- AssertNotErrorIs
- AssertNotImplements
- AssertNotInRange
- AssertNotKindOf
- AssertNotNil
- AssertNotNumeric
- AssertNotPanics
- AssertNotRegexp
- AssertNotSameElements
- AssertNotUnique
- [AssertNotZero](https://github.com/MarvinJWendt/testza#Assert
