testify icon indicating copy to clipboard operation
testify copied to clipboard

Add opportunity to trigger setup/teardown for subtest

Open qerdcv opened this issue 3 years ago • 0 comments

Summary

Add opportunity to setup or teardown each subtest

Changes

  • Added method to the Suite struct that allows to save parent suite (with it's methods) and execute it in future
  • Added SetupSubTest interface that allows to execute function before each subtest
  • Added TearDownSubTest interface that allows to execute function after each subtest is done

Motivation

I find very useful to have opportunity to setup/tear down subtest, and I decide to try add it.

Example usage

type MySuite struct {
    suite.Suite
    db *sql.DB
} 

func (ms *MySuite) SetupSuite() {
   // abstract code
   // setup database in test container and save it into the ms.db
}

func (ms *MySuite) TearDownSubTest() {
    // abstract code
    // after each subtest run I need to cleanup db
    // to avoid conflicts in my tests and make tests more isolated from each other
}

Related issues

Closes: #1031 Closes: #832

qerdcv avatar Aug 08 '22 22:08 qerdcv