Skip to content

Test status does not flow from TestSetup to its running Test #128

@christothes

Description

@christothes

Given a test suite with a TestSetup method, if c.Fail() is called on the *C instance captured from the TestSetup method or one of its descendants after TestSetup completes but before the Test method completes, the test is not marked failed.

Consider the following test:

package main

import (
	chk "gopkg.in/check.v1"
	"testing"
)

type scratchTest struct {
	c *chk.C
}

// Hookup to the testing framework
func Test(t *testing.T) { chk.TestingT(t) }

var _ = chk.Suite(&scratchTest{})

func (s *scratchTest) TestCheckDoesNotFlow(c *chk.C) {
	s.doFail()
	c.Log("This test should be failing")
}

func (s *scratchTest) SetUpTest(c *chk.C) {
	// capture the check test context
	s.c = c
}

func (s *scratchTest) doFail() {
	s.c.Fail()
}

Actual output:

OK: 1 passed
PASS
ok      _/C_/src/goscratch      0.126s

Expected output:

----------------------------------------------------------------------
FAIL: checkrepro_test.go:20: scratchTest.TestCheckDoesNotFlow

This test should be failing
OOPS: 0 passed, 1 FAILED
--- FAIL: Test (0.00s)
FAIL
exit status 1
FAIL    chrissscratch.com/scratch       0.105s

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions