Code Monkey home page Code Monkey logo

Comments (2)

matryer avatar matryer commented on May 22, 2024

I would love to add this to Testify.

On 1 Aug 2013, at 14:36, nelsam [email protected] 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.

from testify.

matryer avatar matryer commented on May 22, 2024

Done

from testify.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.