有条件地运行测试,生成标志不起作用

Pab*_*dez 0 testing conditional-compilation go property-based-testing

我在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)
    }
}
Run Code Online (Sandbox Code Playgroud)

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

知道什么是错的吗?

小智 5

你的// + build慢需要跟一个空行

要将构建约束与包文档区分开来,必须在一系列构建约束后面加一个空行.

访问Build Constraints