Filtering a type of test in the whole project

133 views
Skip to first unread message

Johan Martinsson

unread,
Feb 8, 2021, 9:02:54 AM2/8/21
to golang-nuts
I would like to separate my tests into different test suites. The first one is the regular unit tests and the second one is tests that might fail from time to time (they include external web services). 

The ways to do this go that I have found are
  1. Use build tags
  2. Provide a list of files to go test
  3. Use the -run flag and a regex of test method names
However none fits my need: 

1.
I'm not happy with it as if I don't want to run the unit tests in the second suite, then I have to add a build-flag to my unit tests as well

2. 
All files have to be in the same directory. I could put all those tests in one directory, but I want to keep my test files where they belong from a functional view 

3. 
Same problem as 2. everything has to be in the same directory

Am I missing some option here?
 

Jan Mercl

unread,
Feb 8, 2021, 9:10:34 AM2/8/21
to Johan Martinsson, golang-nuts
On Mon, Feb 8, 2021 at 3:03 PM Johan Martinsson
<martinss...@gmail.com> wrote:

> Am I missing some option here?

It's additionally possible to use a test flag like -mayfail and call
flag.Parse() in TestMain().

Jakob Borg

unread,
Feb 8, 2021, 10:08:23 AM2/8/21
to Johan Martinsson, golang-nuts
A couple of additional possibilities might be to use the -short flag (have network dependent tests look at testing.Short() and skip) or using environment variables (only run network tests when some variable is set).

//jb

On 8 Feb 2021, at 15:03, Johan Martinsson <martinss...@gmail.com> wrote:

I would like to separate my tests into different test suites. The first one is the regular unit tests and the second one is tests that might fail from time to time (they include external web services). 
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/89989af1-9435-4ea7-b776-b1fd431bbd56n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages