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

Exclusive Convey #52

Closed
joliver opened this issue Oct 17, 2013 · 15 comments
Closed

Exclusive Convey #52

joliver opened this issue Oct 17, 2013 · 15 comments

Comments

@joliver
Copy link

joliver commented Oct 17, 2013

Could you please add the ability the run only a specific convey? This would eliminate the need to use SkipConvey on other sections. Perhaps it could be called OnlyConvey or something similar.

@ghost ghost assigned mdwhatcott Oct 18, 2013
@mdwhatcott
Copy link
Collaborator

@joliver - As I see it right now, the only thing we could do with certainty is ignore all other Convey calls within the same story as well as any future stories. I can't determine what other stories might be run before the story with an 'Exclusive' Convey. Also, I'm assuming that any child Convey calls that are contained within the marked Convey would also be run.

@joliver
Copy link
Author

joliver commented Oct 19, 2013

@mdwhatcott Agreed. Only within the same story and all sub-conveys within the marked/exclusive convey would be run.

@mdwhatcott
Copy link
Collaborator

@joliver lets back up and ask the question "why do we sometimes want to run a single scope?" Is it usually to limit output because of all the repeated/isolated test runs? If so, I've discovered that the log package can be used for debug output really effectively, such that ioutil.Discard is used as the writer (noop), except for the scope in question, which could make use of os.Stdout.

@joliver
Copy link
Author

joliver commented Nov 8, 2013

Sometimes I single out a scope so I can try debugging the application code
On Nov 7, 2013 8:51 PM, "Michael Whatcott" [email protected] wrote:

@joliver https://github.com/joliver lets back up and ask the question
"why do we sometimes want to run a single scope?" Is it usually to limit
output because of all the repeated/isolated test runs? If so, I've
discovered that the log package can be used for debug output really
effectively, such that ioutil.Discard is used as the writer (noop), except
for the scope in question, which could make use of os.Stdout.


Reply to this email directly or view it on GitHubhttps://github.com//issues/52#issuecomment-28032842
.

@mdwhatcott
Copy link
Collaborator

@joliver Yes and usually the debugging consists of a few scattered print statements. The output of those print statements tends to multiply when lots of Conveys are executing the same production code over and over, hence the need to isolate a particular Convey. The solution I'm thinking about allows the tester the ability to turn output on and off for selected Convey scopes but doesn't necessarily skip any Conveys. This solution would be convenient because it doesn't require any change to GoConvey, just skilled usage of the log package or even the fmt package to redirect/select output as needed.

@mdwhatcott
Copy link
Collaborator

Here's an example of using the log package to select/filter output. Notice that we set all logging to be discarded near or at the top-level Convey. Then, deeper in we set the log outptut to be a valid writer (like os.Stdout) and only get the output you need. The downside is that you have to mess with importing "log", "os", and "ioutil" in your test code if you don't have them already. And it means that you use "log" instead of "fmt" in your production code (which isn't really a downside, just an observation).

func TestScoring(t *testing.T) {
    Convey("Subject: Bowling Game Scoring", t, func() {
        var game *Game // Whatever you do, don't do this: game := NewGame()
        // Otherwise nested closures won't reference the correct instance

        Convey("Given a fresh score card", func() {
            log.SetOutput(ioutil.Discard)
            log.SetFlags(0) // gets rid of datetime prefix (optional)

            game = NewGame()

            Convey("When all gutter balls are thrown", func() {
                game.rollMany(20, 0)

                Convey("The score should be zero", func() {
                    So(game.Score(), ShouldEqual, 0)
                })
            })

            Convey("When all throws knock down only one pin", func() {
                log.SetOutput(os.Stdout) // NOTE: enable logging for this test...
                game.rollMany(20, 1)

                Convey("The score should be 20", func() {
                    So(game.Score(), ShouldEqual, 20)
                })
            })

  // Rest of code omitted for example...
}

@joliver
Copy link
Author

joliver commented Nov 8, 2013

This could work unless we start using gdb in which case we'd be able to set
breakpoints and then we'd have to start doing SkipConvey for things we
didn't want to include in the test.

On Fri, Nov 8, 2013 at 10:34 AM, Michael Whatcott
[email protected]:

Here's an example of using the log package to select/filter output. Notice
that we set all logging to be discarded near or at the top-level Convey.
Then, deeper in we set the log outptut to be a valid writer (like
os.Stdout) and only get the output you need. The downside is that you have
to mess with importing "log", "os", and "ioutil" in your test code if you
don't have them already. And it means that you use "log" instead of "fmt"
in your production code (which isn't really a downside, just an
observation).

func TestScoring(t *testing.T) {
Convey("Subject: Bowling Game Scoring", t, func() {
var game *Game // Whatever you do, don't do this: game := NewGame()
// Otherwise nested closures won't reference the correct instance

    Convey("Given a fresh score card", func() {
        log.SetOutput(ioutil.Discard)
        log.SetFlags(0) // gets rid of datetime prefix (optional)

        game = NewGame()

        Convey("When all gutter balls are thrown", func() {
            game.rollMany(20, 0)

            Convey("The score should be zero", func() {
                So(game.Score(), ShouldEqual, 0)
            })
        })

        Convey("When all throws knock down only one pin", func() {
            log.SetOutput(os.Stdout) // NOTE: enable logging for this test...
            game.rollMany(20, 1)

            Convey("The score should be 20", func() {
                So(game.Score(), ShouldEqual, 20)
            })
        })

// Rest of code omitted for example...
}


Reply to this email directly or view it on GitHubhttps://github.com//issues/52#issuecomment-28081476
.

@mdwhatcott
Copy link
Collaborator

Yes, good point. I'll continue thinking about how to go about this. The log workaround will help for now though (I think).

@mdwhatcott
Copy link
Collaborator

Not quite sure how to go about this yet so we are deferring this issue. It will be referenced on the wiki for future discussion.

@mdwhatcott
Copy link
Collaborator

@joliver - Well, I'm a bit embarrassed at how simple the solution was and how long it took me to come up with. The only slight change is that you have to start by calling FocusConvey at the top-level and then drill down all the way to the leaf-node Convey, changing each Convey in the chain to FocusConvey. Everything else in that suite will be ignored. Happy debugging!

@danielalves
Copy link

Hey, this (quite old) feature is what I was looking for! It would be great if it was documented in the Wiki so other people can find it faster 😄

@mdwhatcott
Copy link
Collaborator

The wiki is open for editing--feel free to create a page if you'd like. @danielalves

@danielalves
Copy link

👍

@elibdev
Copy link

elibdev commented Mar 21, 2019

Added a basic summary and usage example to the wiki: https://github.com/smartystreets/goconvey/wiki/Skip#running-only-certain-convey-registrations

@ezk84
Copy link
Contributor

ezk84 commented Dec 8, 2022

Is it not possible to have just a single deep FocusConvey, similar to the way jasmine allows a fit to just run a single test case without having to change the describe to fdescribe?

Having to change all conveys up the tree doesn't really allow to quickly run a single problematic test case.

mdwhatcott added a commit that referenced this issue Jun 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants