-
Notifications
You must be signed in to change notification settings - Fork 79
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
Test hooks should not execute if all tests are skipped #103
Comments
This is the work-around we're currently using, a bit clumsy: // Goblin is a partial interface for grabbing the funcs we need
type Goblin interface {
It(string, ...interface{})
Xit(string, ...interface{})
Before(func())
BeforeEach(func())
JustBeforeEach(func())
After(func())
AfterEach(func())
// Goblin funcs
Assert(interface{}) *goblin.Assertion
Fail(interface{})
FailNow()
Failf(string, ...interface{})
Fatalf(string, ...interface{})
Errorf(string, ...interface{})
Helper()
}
type Skip struct {
Goblin
}
func (this *Skip) It(name string, h ...interface{}) {
this.Goblin.Xit(name, h...)
}
func (this *Skip) Before(f func()) {
}
func (this *Skip) BeforeEach(f func()) {
}
func (this *Skip) JustBeforeEach(f func()) {
}
func (this *Skip) After(f func()) {
}
func (this *Skip) AfterEach(f func()) {
}
// SkipIf returns a wrapped Goblin object if noSkip is false, otherwise it
// returns the normal Goblin instance passed in.
func SkipIf(g *goblin.G, noSkip bool) Goblin {
if noSkip {
return g
}
// Skip holds noop functions for skipping tests
skip := &Skip{g}
return skip
} |
This is not a valid example since it doesn't contain a
What do you mean with this? Parity with what exactly? I think an alternative here would be to also provide a |
func MyTest(...){
g := Goblin(...)
g.Describe("no tests", func (){
g.Before(func () {
fmt.Println("This never runs because there are no tests.")
})
})
g.Describe("one skipped test", func (){
g.Before(func (){
fmt.Println("This will run because there is a declared test, even tho it's empty and skipped")
})
g.Xit("placeholder test")
})
} ... having gotten into the code more this is because So this was unexpected behavior/non-parity between what I assumed were similar test suite states (e.g. no tests, or just skipped tests).
I've gone ahead and implemented an alternative in #106 that handles a variety of cases with tests... I'm using that successfully from my fork but would love to see it make it back upstream. /cc @marcosnils |
For example:
This test suite should be a no-op, but will take action in the hooks (Before, After, etc.) even so.
This would be parity with the behavior when no tests are declared but there are hooks present.
My use case is using
Before
hooks to set up external services for the tests. We also allow a "fast" test mode when the services aren't present (by wrappingIt
andXit
from an environment flag).Alternatively: Add a
g.SkipIf(bool)
to skip entire test suites if the passed value is true/false.The text was updated successfully, but these errors were encountered: