houqp / gtest

Go test utility library inspired by pytest
https://godoc.org/github.com/houqp/gtest
MIT License
31 stars 0 forks source link

asserts in Setup, BeaforeEach does not stop SubTest execution #2

Open vk-coder opened 1 year ago

vk-coder commented 1 year ago

gtest v1.0.0

Setup and BeforeEach are supposed to setup environment before each Test Group and Sub Test. If these methods assert then it is expected that no SubTests are executed in the group. But go test still proceeds further and causes incorrect behaviour reporting.

In following example (both // Sample 1 and // Sample 2), SubTestSample1 should never get executed but in reality it does.

I am using -failfast flag while running go test

/usr/local/go/bin/go test -timeout 30s -run ^TestSampleTests$ automation -failfast

func setupNetwork(t *testing.T) {
    assert.Nil(t, nil)
}

type MyTests struct {}

// Sample 1
func (s * MyTests) Setup(t *testing.T) {
    setupNetwork()
}

// Sample 2
func (s * MyTests) Setup(t *testing.T) {
    assert.Nil(t, nil)
}

func (s *MyTests) Teardown(t *testing.T) {}
func (s *MyTests) BeforeEach(t *testing.T) {}
func (s *MyTests) AfterEach(t *testing.T) {}

func (s *MyTests) SubTestSample1(t *testing.T) {
}

func TestSampleTests(t *testing.T) {
    gtest.RunSubTests(t, &MyTests{})
}