Skip to content

Commit a2d37ee

Browse files
cweillclaude
andcommitted
docs: add Quick Start Examples section to README
Added a comprehensive "Quick Start Examples" section to help new users get started quickly with gotests. The section includes: Examples: - Generate tests for a single function (with full output) - Generate tests for all exported functions - Generate tests recursively with ./... pattern - Generate tests with testify template - Common workflows with practical use cases Each example shows both the command and explains what it does, making it easier for users to understand how to use gotests effectively. The examples are placed right after the options list and before the Go Generics section for better flow and discoverability. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 9487fc4 commit a2d37ee

File tree

1 file changed

+85
-0
lines changed

1 file changed

+85
-0
lines changed

README.md

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,91 @@ Available options:
6565
-version print version information and exit
6666
```
6767

68+
## Quick Start Examples
69+
70+
### Generate tests for a single function
71+
72+
Given a file `math.go`:
73+
74+
```go
75+
package math
76+
77+
func Add(a, b int) int {
78+
return a + b
79+
}
80+
```
81+
82+
Generate a test:
83+
84+
```sh
85+
$ gotests -only Add -w math.go
86+
```
87+
88+
This creates `math_test.go` with:
89+
90+
```go
91+
func TestAdd(t *testing.T) {
92+
type args struct {
93+
a int
94+
b int
95+
}
96+
tests := []struct {
97+
name string
98+
args args
99+
want int
100+
}{
101+
// TODO: Add test cases.
102+
}
103+
for _, tt := range tests {
104+
t.Run(tt.name, func(t *testing.T) {
105+
if got := Add(tt.args.a, tt.args.b); got != tt.want {
106+
t.Errorf("Add() = %v, want %v", got, tt.want)
107+
}
108+
})
109+
}
110+
}
111+
```
112+
113+
### Generate tests for all exported functions
114+
115+
```sh
116+
$ gotests -all -exported -w .
117+
```
118+
119+
This generates tests for all exported functions in the current directory.
120+
121+
### Generate tests recursively
122+
123+
```sh
124+
$ gotests -all -w ./...
125+
```
126+
127+
This generates tests for all functions in the current directory and all subdirectories.
128+
129+
### Generate tests with testify
130+
131+
```sh
132+
$ gotests -all -template testify -w calculator.go
133+
```
134+
135+
This generates tests using the [testify](https://github.com/stretchr/testify) assertion library.
136+
137+
### Common workflows
138+
139+
```sh
140+
# Generate tests for all exported functions in a package
141+
$ gotests -exported -w pkg/*.go
142+
143+
# Generate only tests for specific functions matching a pattern
144+
$ gotests -only "^Process" -w handler.go
145+
146+
# Generate tests excluding certain functions
147+
$ gotests -all -excl "^helper" -w utils.go
148+
149+
# Generate parallel subtests
150+
$ gotests -all -parallel -w service.go
151+
```
152+
68153
## Go Generics Support
69154

70155
`gotests` fully supports Go generics (type parameters) introduced in Go 1.18+. It automatically generates tests for generic functions and methods on generic types.

0 commit comments

Comments
 (0)