testinggocontinuous-integrationtddgoconvey

Why GoConvey Tests fail with error code 0?


I need to run my GoConvey tests as part of my build how do i make sure go test exits with error exit code (not 0)?


Solution

  • Ok found the bug:

    I have TestMain in my code that runs before the tests:

    func TestMain(m *testing.M) {
        log.SetOutput(ioutil.Discard) // Disable logs.
        m.Run()
    }
    

    m.Run should be wrapped with os.Exit so it can be used with error status codes:

    func TestMain(m *testing.M) {
        log.SetOutput(ioutil.Discard) // Disable logs.
        os.Exit(m.Run())
    }
    

    that fixed the problem