cweill/gotests là dự án phía máy chủ trên GitHub với 5.3k sao, viết chủ yếu bằng Go. Automatically generate Go test boilerplate from your source code.
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
gotests is a powerful Go test generator that automatically creates table-driven tests from your source code. It analyzes function and method signatures to generate comprehensive test scaffolding, saving you time and ensuring consistency across your test suite.
Key Features
🚀 Zero-config test generation - Works out of the box with any Go project
🎯 Smart test scaffolding - Generates complete table-driven test structure with proper type handling
🔧 Flexible filtering - Generate tests for specific functions, exported functions, or entire packages
📦 Auto-imports - Automatically adds required imports to test files
🧬 Full generics support - Works seamlessly with Go 1.18+ type parameters
🔄 Recursive generation - Process entire directory trees with ./... pattern
🎨 Custom templates - Built-in support for testify and custom test templates
⚡ Parallel subtests - Optional parallel test execution support
Demo
The following shows gotests in action using the official Sublime Text 3 plugin. Plugins also exist for Emacs, also Emacs, Vim, Atom Editor, Visual Studio Code, and IntelliJ Goland.
Installation
Minimum Go version: Go 1.22
Use go install to install and update:
$ go install github.com/cweill/gotests/gotests@latest
Usage
From the commandline, gotests can generate Go tests for specific source files or an entire directory. By default, it prints its output to stdout.
$ gotests [options] PATH ...
Available options:
-all generate tests for all functions and methods
-excl regexp. generate tests for functions and methods that don't
match. Takes precedence over -only, -exported, and -all
-exported generate tests for exported functions and methods. Takes
precedence over -only and -all
-i print test inputs in error messages
-named switch table tests from using slice to map (with test name for the key)
-only regexp. generate tests for functions and methods that match only.
Takes precedence over -all
-nosubtests disable subtest generation when >= Go 1.7
-parallel enable parallel subtest generation when >= Go 1.7.
-w write output to (test) files instead of stdout
-template_dir Path to a directory containing custom test code templates. Takes
precedence over -template. This can also be set via environment
variable GOTESTS_TEMPLATE_DIR
-template Specify custom test code templates, e.g. testify. This can also
be set via environment variable GOTESTS_TEMPLATE
-template_params_file read external parameters to template by json with file
-template_params read external parameters to template by json with stdin
-use_go_cmp use cmp.Equal (google/go-cmp) instead of reflect.DeepEqual
-ai generate test cases using AI (requires Ollama)
-ai-model AI model to use (default "qwen2.5-coder:0.5b")
-ai-endpoint Ollama API endpoint (default "http://localhost:11434")
-ai-min-cases minimum number of test cases to generate with AI (default 3)
-ai-max-cases maximum number of test cases to generate with AI (default 10)
-version print version information and exit
AI-Powered Test Generation
gotests can generate intelligent test cases using local LLMs via Ollama. This feature analyzes your function implementations and generates realistic test values, edge cases, and error conditions.
Quick Start
Install Ollama (https://ollama.ai)
Pull a model:
ollama pull qwen2.5-coder:0.5b # Small, fast model (400MB)
# or
ollama pull llama3.2:latest # Larger, more capable (2GB)
Generate tests with AI:
gotests -all -ai -w yourfile.go
Example
Given this function:
func CalculateDiscount(price float64, percentage int) (float64, error) {
if price < 0 {
return 0, errors.New("price cannot be negative")
}
if percentage < 0 || percentage > 100 {
return 0, errors.New("percentage must be between 0 and 100")
}
discount := price * float64(percentage) / 100.0
return price - discount, nil
}
The AI generates (showing 3 cases; by default, the AI generates between 3-10 cases):
# Use a different model
gotests -all -ai -ai-model llama3.2:latest -w yourfile.go
# Generate a specific number of test cases (min = max)
gotests -all -ai -ai-min-cases 5 -ai-max-cases 5 -w yourfile.go
# Generate a range of test cases (AI chooses between 3-7)
gotests -all -ai -ai-min-cases 3 -ai-max-cases 7 -w yourfile.go
# Combine with other flags
gotests -exported -ai -parallel -w yourfile.go
How It Works
Analyzes function implementation and logic
Generates realistic test values based on actual code
Creates test cases for edge cases and error conditions
Function signatures (name, parameters, return types)
Complete function bodies including all code and comments
No file paths or project context
Privacy considerations:
⚠️ Function bodies may contain sensitive information - business logic, algorithms, or credentials/secrets in comments
✅ Local-first by default - Using Ollama keeps all data on your machine; nothing is sent to external servers
✅ Offline operation - AI generation works completely offline with local models
🔒 Recommendation: Avoid using -ai on code containing secrets, API keys, or proprietary algorithms in comments
If using cloud providers in the future:
Function source code will be transmitted to the cloud provider's API
Review the provider's data retention and privacy policies
Consider using -ai only on non-sensitive codebases
Quick Start Examples
Generate tests for a single function
Given a file math.go:
package math
func Add(a, b int) int {
return a + b
}
Generate a test:
$ gotests -only Add -w math.go
This creates math_test.go with:
func TestAdd(t *testing.T) {
type args struct {
a int
b int
}
tests := []struct {
name string
args args
want int
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := Add(tt.args.a, tt.args.b); got != tt.want {
t.Errorf("Add() = %v, want %v", got, tt.want)
}
})
}
}
Generate tests for all exported functions
$ gotests -all -exported -w .
This generates tests for all exported functions in the current directory.
Generate tests recursively
$ gotests -all -w ./...
This generates tests for all functions in the current directory and all subdirectories.
Generate tests with testify
$ gotests -all -template testify -w calculator.go
This generates tests using the testify assertion library.
Common workflows
# Generate tests for all exported functions in a package
$ gotests -exported -w pkg/*.go
# Generate only tests for specific functions matching a pattern
$ gotests -only "^Process" -w handler.go
# Generate tests excluding certain functions
$ gotests -all -excl "^helper" -w utils.go
# Generate parallel subtests
$ gotests -all -parallel -w service.go
Go Generics Support
gotests fully supports Go generics (type parameters) introduced in Go 1.18+. It automatically generates tests for generic functions and methods on generic types.
Example: Generic Function
Given this generic function:
func FindFirst[T comparable](slice []T, target T) (int, error) {
for i, v := range slice {
if v == target {
return i, nil
}
}
return -1, ErrNotFound
}
cweill/gotests có 5.3k sao GitHub — tải lại trang để xem số mới nhất, hoặc xem trực tiếp github.com/cweill/gotests. TopGit phản chiếu số sao của GitHub nhưng không cam kết đến từng phút.
cweill/gotests có phải mã nguồn mở không?
Có — cweill/gotests phát hành theo license Apache-2.0, nghĩa là mã nguồn mở để đọc, fork và (tùy license) tái sử dụng. Mã: github.com/cweill/gotests.
cweill/gotests còn đang phát triển không?
Commit gần nhất trên cweill/gotests là 1.0 năm trước (theo timestamp GitHub). Repo có 354 fork — một chỉ báo về mức độ quan tâm của cộng đồng.
cweill/gotests là gì?
cweill/gotests (cweill/gotests) là dự án Go trên GitHub. Theo mô tả gốc: Automatically generate Go test boilerplate from your source code.
cweill/gotests so với các dự án Backend khác thế nào?
cweill/gotests được TopGit xếp vào nhóm Backend, với 5.3k sao GitHub và viết bằng Go. Xem trang chủ đề Backend trên TopGit để so sánh với các dự án tương tự theo số sao và mức độ hoạt động.
Đọc thêm về cweill/gotests ở đâu?
Trang TopGit này là một snapshot — tab "Readme" hiển thị nguyên văn README của repo (đã bỏ link, giữ ảnh). Repo GitHub ở github.com/cweill/gotests là nguồn chính thức.
Đọc đầy đủ README ở tab phía trên.
Chưa chắc gotests có hợp với bạn?
Để ChatGPT, Claude hoặc Perplexity tìm hiểu giúp — bấm bên dưới và xem AI nói gì về gotests.