Documentation
¶
Overview ¶
Package testutil 测试辅助工具
使用:
func TestXxx(t *testing.T) {
testutil.SetupTestDB(t)
// g.DB() 已指向 codcms_test
// 使用 service.Article().Add/Get/Edit/Del ...
}
环境准备:
CREATE DATABASE codcms_test CHARACTER SET utf8mb4; mysql codcms_test < sql/codcms.sql
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CleanupTables ¶
CleanupTables deletes all rows from the specified tables (for test isolation). Call at the start of each test function that modifies data to prevent state coupling. 清理指定表的所有数据,用于测试隔离。每个会修改数据的测试函数开头调用。
func SetupTestDB ¶
SetupTestDB 注入测试数据库配置到 g.DB()。 每个 TestXxx 函数调用一次,sync.Once 保证只初始化一次。
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.