Comments (2)
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.
Done
from testify.
Related Issues (20)
- assert: add `ContainsFunc` to check a slice by func assertion HOT 2
- Add `Subset`/`ElementsMatch` by func assertion HOT 1
- use of mock HOT 1
- assert: accept values with named types in `InDelta*`, `InEpsilon*` HOT 2
- assert: EqualBody to check if two io.Readers have same data HOT 1
- suite.TestTeardown fail/panic is shadowing the cause panic HOT 2
- proposal: analogue of `InDeltaMapValues` with different deltas HOT 2
- proposal: new assertion`InEpsilonMapValues` HOT 3
- assert package deserve to be STD HOT 1
- Detect and fail on `require.*` methods called from a wrong goroutine HOT 5
- suite: TestSubtestPanic is failing HOT 6
- suite: missing signature check before calling Test* method HOT 3
- Support colorized output, indentation in accordance with subtest depth, and one more assertion HOT 3
- wall clock HOT 10
- assert.EqualExportedValues - panic: reflect.MakeSlice of non-slice type [recovered] HOT 6
- `suite.Require` deadlock HOT 1
- Assert: go test output shows subtests that fail as PASS HOT 3
- `YAMLEq` does not validate YAML HOT 1
- Is it possible to assert for multiple allowed values? HOT 2
- Proposal: guard or support comparing with untyped nil HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from testify.