duanmou9228 2016-11-05 01:04
浏览 43

我可以在套件中运行一个测试吗?

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?

  • 写回答

2条回答 默认 最新

  • doutou1922 2016-11-07 20:20
    关注

    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
    
    评论

报告相同问题?

悬赏问题

  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法