Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Buildup/Teardown #19

Closed
nelsam opened this issue Aug 1, 2013 · 2 comments
Closed

Buildup/Teardown #19

nelsam opened this issue Aug 1, 2013 · 2 comments

Comments

@nelsam
Copy link
Contributor

nelsam commented Aug 1, 2013

Many testing libraries provide some method of defining common building up and tearing down functionality for the testing environment. I'm not sure if this type of functionality is something that would fit with the goals of testify, but it's a fairly common type of functionality that simplifies code for a number of use cases.

An example of a common case:

func BuildupTestEnv() {
    InsertToTestDB(testingData)
}

func TeardownTestEnv() {
    TruncateTestDB()
}

func TestGetWithID(t *testing.T) {
    BuildupTestEnv() // run at the beginning of every test
    [...testing code...]
    TeardownTestEnv() // run at the end of every test
}

The "go test" command doesn't provide anything like this, so most testing frameworks get around this by doing something like the following:

import (
    "testify"
)

type ControllerTestSuite struct{
    testify.Suite
}

// This function will be run by the "go test" command
func TestRun(t *testing.T) {
    suite := new(ControllerTestSuite)
    testify.RunSuite(suite)
}

// Run by testify.RunSuite(suite) before each test
func (suite *ControllerTestSuite) BeforeTest() {
    InsertToTestDB(testingData)
}

// Run by testify.RunSuite(suite) after each test
func (suite *ControllerTestSuite) AfterTest() {
    TruncateTestDB()
}

// Run by testify.RunSuite(suite) as a test, after running BeforeTest() but
// before running AfterTest()
func (suite *ControllerTestSuite) TestGetWithID() {
    [...testing code...]
}

Here are two example testing libraries in Go that support buildup and teardown methods, using the "go test" tool:

http://labix.org/gocheck (See: http://labix.org/gocheck#fixtures for buildup and teardown)

https://github.com/remogatto/prettytest (See: https://github.com/remogatto/prettytest/blob/master/prettytest_test.go#L102-120 for buildup and teardown)

@matryer
Copy link
Member

matryer commented Aug 2, 2013

I would love to add this to Testify.

On 1 Aug 2013, at 14:36, nelsam notifications@github.com wrote:

Many testing libraries provide some method of defining common building up and tearing down functionality for the testing environment. I'm not sure if this type of functionality is something that would fit with the goals of testify, but it's a fairly common type of functionality that simplifies code for a number of use cases.

An example of a common case:

func BuildupTestEnv() {
InsertToTestDB(testingData)
}

func TeardownTestEnv() {
TruncateTestDB()
}

func TestGetWithID(t *testing.T) {
BuildupTestEnv() // run at the beginning of every test
[...testing code...]
TeardownTestEnv() // run at the end of every test
}
The "go test" command doesn't provide anything like this, so most testing frameworks get around this by doing something like the following:

import (
"testify"
)

type ControllerTestSuite struct{
testify.Suite
}

// This function will be run by the "go test" command
func TestRun(t *testing.T) {
suite := new(ControllerTestSuite)
testify.RunSuite(suite)
}

// Run by testify.RunSuite(suite) before each test
func (suite *ControllerTestSuite) BeforeTest() {
InsertToTestDB(testingData)
}

// Run by testify.RunSuite(suite) after each test
func (suite *ControllerTestSuite) AfterTest() {
TruncateTestDB()
}

// Run by testify.RunSuite(suite) as a test, after running BeforeTest() but
// before running AfterTest()
func (suite *ControllerTestSuite) TestGetWithID() {
[...testing code...]
}
Here are two example testing libraries in Go that support buildup and teardown methods, using the "go test" tool:

http://labix.org/gocheck (See: http://labix.org/gocheck#fixtures for buildup and teardown)

https://github.com/remogatto/prettytest (See: https://github.com/remogatto/prettytest/blob/master/prettytest_test.go#L102-120 for buildup and teardown)


Reply to this email directly or view it on GitHub.

@matryer
Copy link
Member

matryer commented Jan 28, 2014

Done

@matryer matryer closed this as completed Jan 28, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants