Your Convey needs more Focus

February 7, 2014

One of the great benefits of TDD/BDD is that you usually don't have to spend much, if any time at all in a debugger. To enter a debugger is to admit a loss of control over the system under test. Even so, there are times when you do need to debug something, even if you're maintaining the discipline.

Lately, most of my coding is in GoLang. Coming from using an IDE almost exclusively to write Python (using PyCharm) and C# (using VS and ReSharper), and knowing how great the visual debugging tools are it's hard to fathom using a console-based debugger for GoLang code. Yes, I know about godbg, which is an amazing tool, but I would rather stay in my test runner of choice, which is GoConvey.

Up until now I would do something like this to achieve debugging:

  • Add log.Println statements where the bugs are
  • Use SkipConvey to limit execution to the test in question (this can get tedious if the test suite is large)
  • Run the tests and observe the output


  • Add the logging statements
  • Use an init function in the test code to substitute a nil writer to the logger
  • Substitute stdout in the Convey scope that executes the code with logging
  • run the tests and observe the output


Now, there's a better way. It still means putting in some logging, which may or may not be temporary. But, all you have to do now is something like this:

FocusConvey("Subject: Integer incrementation and decrementation", t, func() {
	var x int

	FocusConvey("Given a starting integer value", func() {
		x = 42

		FocusConvey("When incremented", func() {

			Convey("The value should be greater by one", func() {
				So(x, ShouldEqual, 43)
			FocusConvey("The value should NOT be what it used to be", func() {
				So(x, ShouldNotEqual, 42)
		Convey("When decremented", func() {

			Convey("The value should be lesser by one", func() {
				So(x, ShouldEqual, 41)
			Convey("The value should NOT be what it used to be", func() {
				So(x, ShouldNotEqual, 42)
		Reset(func() {
			x = 0

In this code, only those scopes declared with FocusConvey will be executed, the reset will be ignored. Much easier to toggle for debugging purposes.

Of course, you shouldn't leave the test suite with a bunch of FocusConvey calls lying around. After you fix your code get rid of the Focus and just keep Convey.

Happy debugging!

Subscribe to our blog!
Learn more about RSS feeds here.
Subscribe Now
Get our latest eBook!
Evaluating a geocoding tool?
Get the buyer's guide
smarty logo
Download now
Read our recent posts
Rising Parcel Shipping Costs in 2022: How to Cut Your Shipping Expenses
Arrow Icon
Parcel shipping costs have been rising since 2020. We’ve all seen inflation on the consumer end, whether we’re checking out online or paying at the gas pump. And skyrocketing freight rates have made headlines. Today, we’re going to focus on the impact of the increasing cost of shipping on your business and what you can do about it. But don’t lose hope—while we’re going to explore climbing shipment costs in this article, we’ll also chat about what your business can do to make shipping more efficient.
How to Clean Address Data For the Holiday Rush
Arrow Icon
It’s November, and online shopping is ramping up to its climactic end-of-year blitz. www. blackfriday. com estimates that between Thanksgiving and Black Friday of this year, consumers will spend approximately $13 billion 1. That’s great news for your business. But if you don’t have the right tools in place to help you meet that demand, you might be left wishing you had better prepare. Staffing may be one issue for many businesses. According to the US Chamber of Commerce, the wholesale and retail trade industry has experienced the second-highest quit rate of all industries since November 20202.
Helpful Hints to Authenticating Your APIs
Arrow Icon
We brought out the big guns in the way of our Development Team Lead, Kent Gividen, in a webinar all about authenticating your APIs. He went over some of his most useful tips and tricks that he uses to ensure APIs are authenticated. Was it helpful? You betcha. You wanna get the sparknotes? Read on. Common and Not-So-Common APIs to Know About Kent began by outlining the APIs that he has run into the most in his years as a developer. Some of them he dug into a little deeper than others, but these are all useful to be aware of.

The leader in location data intelligence

Ready to get started?