如何在go框架中为不同的测试强制执行测试顺序?

如何在go框架中为不同的测试强制执行测试顺序?

问题描述:

If I have different packages and each have a test file (pkg_test.go) is there a way for me to make sure that they run in a particular order ?

Say pkg1_test.go gets executed first and then the rest.

I tried using go channels but it seems to hang.

如果我有不同的软件包并且每个软件包都有一个测试文件( pkg_test.go code>)是 有一种方法可以确保它们按特定顺序运行? p>

pkg1_test.go code>首先执行,然后执行其余命令。 p>

我尝试使用转到频道,但似乎挂起了。 p> div>

It isn't obvious, considering a go test ./... triggers test on all packages... but runs in parallel: see "Go: how to run tests for multiple packages?".

go test -p 1 would run the tests sequentially, but not necessarily in the order you would need.

A simple script calling go test on the packages listed in the right expected order would be easier to do.