小编Cra*_*nes的帖子

在Go中分离单元测试和集成测试

GoLang中是否存在分离单元测试和集成测试的最佳实践(作证)?我有混合的单元测试(不依赖于任何外部资源,因此运行速度非常快)和集成测试(它依赖于任何外部资源,因此运行速度较慢).因此,我希望能够控制是否包含集成测试go test.

最直接的技术似乎是在main中定义-integrate标志:

var runIntegrationTests = flag.Bool("integration", false
    , "Run the integration tests (in addition to the unit tests)")
Run Code Online (Sandbox Code Playgroud)

然后在每个集成测试的顶部添加一个if语句:

if !*runIntegrationTests {
    this.T().Skip("To run this test, use: go test -integration")
}
Run Code Online (Sandbox Code Playgroud)

这是我能做的最好的吗?我搜索了testify文档,看看是否有一个命名约定或者某些内容为我完成了这个,但没有找到任何东西.我错过了什么吗?

integration-testing unit-testing go testify

82
推荐指数
5
解决办法
4万
查看次数

标签 统计

go ×1

integration-testing ×1

testify ×1

unit-testing ×1