Pinpoint: A virtual user conference Register today
Smarty

Your Convey needs more focus

Smarty header pin graphic
Updated July 2, 2025
Tags
Smarty header pin graphic

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

Or...

  • 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

Yuck.

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() {
			x++

			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() {
			x--

			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.
rss feed icon
Subscribe Now
Read our recent posts
Empowering finance, healthcare & insurance companies with international autocomplete
Arrow Icon
Address data plays a vital role for finance, healthcare, and insurance companies. When these companies serve customers worldwide, processes like KYC compliance, fraud prevention, and onboarding become even more complicated, making accurate data even more essential. Enter International Address Autocomplete, a form and checkout address-filling feature that saves the day for more than just ecommerce companies based in the US. It’s also great for finance, healthcare, and insurance companies worldwide.
Inside Smarty - Dallin Davis
Arrow Icon
Get to know Smarty’s favorite Data Analyst, Dallin Davis! On our Business Intelligence team, Dallin’s love of programming—we’re talking R, SAS, SQL, Python, AND Linux—understanding of statistics, and ability to solve any problem thrown his way make him an absolute all-star. Let’s meet Dallin!You have to explain your role at Smarty to a 10-year-old. Go. “Smarty is like a sports team.  Before a team competes against another team, they need to know how they measure up. To do this, they determine who’s winning, who’s losing, and how much they’re winning or losing by.
Open floor Q&A with Smarty developers: A webinar recap
Arrow Icon
Let's be honest, when it comes to addresses, “'close enough” just isn't good enough. At our recent panel discussion with Smarty’s product team members, we really dug deep into what makes address validation work and why it's so crucial for businesses. The themes spanned from Google Maps myths to international quirks, from “non-postal” mysteries to best practices for keeping databases clean. Why Google isn’t the benchmarkOne of the most common statements we hear from other business owners is the “but Google Maps says…” objection.

Ready to get started?