https://github.com/ninedraft/huffy
Tiny package for smart testcase caching
https://github.com/ninedraft/huffy
fuzzing go golang test-automation-project test-generation testing unit-test
Last synced: 4 months ago
JSON representation
Tiny package for smart testcase caching
- Host: GitHub
- URL: https://github.com/ninedraft/huffy
- Owner: ninedraft
- License: mit
- Created: 2019-07-01T09:40:18.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2019-07-13T13:26:56.000Z (almost 7 years ago)
- Last Synced: 2025-12-17T05:28:09.895Z (6 months ago)
- Topics: fuzzing, go, golang, test-automation-project, test-generation, testing, unit-test
- Language: Go
- Homepage:
- Size: 42 KB
- Stars: 7
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# huffy
[](https://goreportcard.com/report/github.com/ninedraft/huffy) [](https://godoc.org/github.com/ninedraft/huffy)
Huffy is a small library for unit testing in symbiosis with test data generators. It allows you to remember the test arguments that caused the fail test. At the next test run, these arguments will be used first.
## Example
```go
// calculate.go
package countchars
// Div must return result of division, rounded to biggest value
func Div(x, y int) int {
return x / y
}
```
```go
// calculate_test.go
package countchars
import (
"math/rand"
"testing"
"github.com/ninedraft/huffy"
)
func TestDiv(test *testing.T) {
type TestCase struct {
X, Y int
Expected int
}
huffy.Tester{
Generator: func(rnd *rand.Rand, id int) interface{} {
var x = rnd.Intn(100) + 2
var y = rnd.Intn(x-1) + 1
var expected = x / y
if x%y != 0 {
expected++
}
return TestCase{
X: x,
Y: y,
Expected: expected,
}
},
Unit: func(test *testing.T, v interface{}) {
var tc = v.(TestCase)
var got = Div(tc.X, tc.Y)
if tc.Expected != got {
test.Fatalf("%d/%d: expected %d, got %d", tc.X, tc.Y, tc.Expected, got)
}
},
}.R(test)
}
```
```bash
go test -timeout 30s github.com/ninedraft/huffy/examples/calculate -run ^(TestDiv)$ -race
```
```
--- FAIL: TestDiv (0.00s)
huffy/examples/calculate/calculate_test.go:34: 44/25: expected 2, got 1
FAIL
FAIL github.com/ninedraft/huffy/examples/calculate 0.041s
Error: Tests failed.
```