Search code examples
testinggoconditional-compilationproperty-based-testing

conditionally running tests with build flags not working


I'm running some tests in golang and I want to avoid running the slow ones, for example this one uses bcrypt so it's slow:

// +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)
    }
}

To avoid running this in every iteration I've set up the // +build slow flag. This should only run when doing go test -tags slow but unfortunately it's running every time (the -v flag shows it's running).

Any idea what's wrong?


Solution

  • Your // +build slow needs to be followed by a blank line

    To distinguish build constraints from package documentation, a series of build constraints must be followed by a blank line.

    visit Build Constraints