包测试的串行执行 [英] Serial execution of package tests

查看:97
本文介绍了包测试的串行执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为web API实施了几个包,每个包都有自己的测试用例。当使用 go test ./api/pkgname 测试每个软件包时,测试通过。如果我想用立即运行所有测试,请去测试./api /...测试用例总是失败。



在每个测试用例中,我使用 DROP SCHEMA public CASCADE ,然后再加上 CREATE SCHEMA public 来重新创建整个模式,然后应用所有迁移。测试套件随机报告错误,说关系/表不存在,所以我想每个测试套件(每个包)都以某种方式并行运行,从而扰乱了DB状态。



我尝试传递一些测试标志,例如 go test -cpu 1 -parallel 0 ./src/api /...,但没有成功。 / p>

这里的问题可以是并行运行的测试吗?如果是的话,我该如何强制执行序列?

  find< dir> -type d -exec go test {} \; 


解决方案

正如其他人所指出的,-parallel不会做这个工作(它只在包内工作)。但是,您可以使用标志-p = 1来连续运行软件包测试。这是记录在这里:



http:// golang。 org / src / cmd / go / testflag.go b
$ b

但(afaict)不在命令行上,去帮助等等。我不确定它意味着坚持(尽管我认为如果它被删除,平行应该是固定的。)


I have implemented several packages for a web API, each with their own test cases. When each package is tested using go test ./api/pkgname the tests pass. If I want to run all tests at once with go test ./api/... test cases always fail.

In each test case, I recreate the entire schema using DROP SCHEMA public CASCADE followed by CREATE SCHEMA public and apply all migrations. The test suite reports errors back at random, saying a relation/table does not exist, so I guess each test suite (per package) is run in parallel somehow, thus messing up the DB state.

I tried to pass along some test flags like go test -cpu 1 -parallel 0 ./src/api/... with no success.

Could the problem here be tests running in parallel, and if yes, how can I force serial execution?

Update:

Currently I use this workaround to run the tests, but I still wonder if there's a better solution

find <dir> -type d -exec go test {} \;

解决方案

As others have pointed out, -parallel doesn't do the job (it only works within packages). However, you can use the flag -p=1 to run through the package tests in series. This is documented here:

http://golang.org/src/cmd/go/testflag.go

but (afaict) not on the command line, go help, etc. I'm not sure it is meant to stick around (although I'd argue that if it is removed, -parallel should be fixed.)

这篇关于包测试的串行执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆