有条件地 运行 测试构建标志不起作用

conditionally running tests with build flags not working

我正在 运行在 golang 中进行一些测试,我想避免 运行 进行缓慢的测试,例如这个使用 bcrypt 所以它很慢:

// +build slow
package services

import (
    "testing"
    "testing/quick"
)

// using bcrypt takes too much time, reduce the number of iterations.
var config = &quick.Config{MaxCount: 20}

func TestSignaturesAreSame(t *testing.T) {
    same := func(simple string) bool {
        result, err := Encrypt(simple)
        success := err == nil && ComparePassWithHash(simple, result)
        return success
    }

    if err := quick.Check(same, config); err != nil {
        t.Error(err)
    }
}

为了避免在每次迭代中都出现 运行,我设置了 // +build slow 标志。在执行 go test -tags slow 时应该只 运行 但不幸的是它每次都是 运行ning(-v 标志显示它是 运行ning)。

知道哪里出了问题吗?

你的// +build slow后面需要跟一个空行

为了区分构建约束和包文档,一系列构建约束后面必须跟一个空行。

访问Build Constraints