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文档,看看是否有一个命名约定或者某些内容为我完成了这个,但没有找到任何东西.我错过了什么吗?