Can I run a single test in a suite?

折月煮酒 提交于 2019-12-07 04:20:52

问题


I have setup a test suite for my struct (https://github.com/stretchr/testify#suite-package). Before I was able to run a single test by specifying just a pattern:

go test -v ./services/gateways/... -run mytest

This approach doesn't work after conversion. Bad luck or is there a way?


回答1:


You can run single methods by specifying the -testify.m argument.

to run this suite method the command is:

go test -v github.com/vektra/mockery/mockery -run ^TestGeneratorSuite$ -testify.m TestGenerator




回答2:


i think you're SOL with that package but here's a similar approach with go 1.7's stock testing tools:

package main

import "testing"

func TestSuite1(t *testing.T) {
    t.Run("first test", func(t *testing.T) { t.Fail() })
    t.Run("second test", func(t *testing.T) { t.Fail() })
}

func TestSuite2(t *testing.T) {
    t.Run("third test", func(t *testing.T) { t.Fatal("3") })
    t.Run("fourth test", func(t *testing.T) { t.Fatal("4") })
}

Example output for one suite:

 therealplato/stack-suites Ω go test -run TestSuite1       
--- FAIL: TestSuite1 (0.00s)
    --- FAIL: TestSuite1/first_test (0.00s)
    --- FAIL: TestSuite1/second_test (0.00s)
FAIL
exit status 1
FAIL    github.com/therealplato/stack-suites    0.005s

Example output for one test:

 therealplato/stack-suites Ω go test -run TestSuite2/third 
--- FAIL: TestSuite2 (0.00s)
    --- FAIL: TestSuite2/third_test (0.00s)
        main_test.go:11: 3
FAIL
exit status 1
FAIL    github.com/therealplato/stack-suites    0.005s


来源:https://stackoverflow.com/questions/40433788/can-i-run-a-single-test-in-a-suite

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!