Sometimes it's nice to ignore or skip an entire scope or some assertions here and there. This is easy with GoConvey.

Skipping Convey registrations

Changing a Convey() to SkipConvey() prevents the func() passed into that call from running. This also has the consequence of preventing any nested Convey registrations from running. The reporter will indicate that the registration was skipped.

  1. SkipConvey("Important stuff", func() { // This func() will not be executed!
  2. Convey("More important stuff", func() {
  3. So("asdf", ShouldEqual, "asdf")
  4. })
  5. })

Using SkipConvey() has nearly the same effect as commenting out the testentirely. However, this is preferred over commenting out tests to avoid theusual "declared/imported but not used" errors. Usage of SkipConvey() isintended for temporary code alterations.

Unimplemented Convey registrations

When composing Convey registrations, sometimes it's convenient to use nil instead of an actual func(). Not only does this skip the scope, but it provides an indication in the report that the registration is not complete, and that it's likely your code is missing some test coverage.

  1. Convey("Some stuff", func() {
  2.  
  3. // This will show up as 'skipped' in the report
  4. Convey("Should go boink", nil)
  5.  
  6. }

Skipping So assertions

Similar to SkipConvey(), changing a So() to SkipSo() prevents the execution ofthat assertion. The report will show that the assertion was skipped.

  1. Convey("1 Should Equal 2", func() {
  2.  
  3. // This assertion will not be executed and will show up as 'skipped' in the report
  4. SkipSo(1, ShouldEqual, 2)
  5.  
  6. })

And like SkipConvey, this function is only intended for use duringtemporary code alterations.

Running Only Certain Convey Registrations

You can use FocusConvey to only run certain Convey registrations.

You must mark at least one leaf Convey registration (where the actual assertions are) and all of its parent Conveys in order for it to work.

Let's see an example:

  1. FocusConvey("A", func() {
  2. // B will not be run
  3. Convey("B", nil)
  4. FocusConvey("C", func() {
  5. // Only D will be run.
  6. FocusConvey("D", func() {
  7. })
  8. })
  9. }

You might want to run all subtests of a certain Convey registration. In that case every leaf test must be marked with Convey, along with all of its parents.

Here's an example of a common mistake:

  1. Convey("A", func() {
  2. // test B will still run because test D is not marked with Focus
  3. Convey("B", nil)
  4. FocusConvey("C", func() {
  5. // Mark test D with Focus to run only test D
  6. Convey("D", func() {
  7. })
  8. })
  9. }

Read more in the documentation on FocusConvey.

End of tutorial

Congrats, you made it! Now go test!