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...
Tags

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 iconSubscribe Now
Read our recent posts
6 Ways Telecom & Internet Companies Leverage Address Data
Arrow Icon
In a recent webinar, we showed how address data tools help managers improve business performance in the following areas:Network PlanningAsset ManagementCustomer Acquisition and RetentionData BlendingMail and Parcel DeliveryFraud Reduction1. Network PlanningAccurate address data plays a critical role in overcoming network planning challenges. We presented solutions at each of the following steps in the network planning process: Clean existing address data with US Address VerificationKeep incoming data clean with US Address AutocompleteMap all addresses using our US Master Address List and hyper-accurate US Rooftop GeocodingAdd context to maps with enriched US Property DataAnalyze, get spatial insights, and make confident business decisions 2.
A Fresh Start: Clean Out Your Computer Day
Arrow Icon
In a world where the lines between digital and physical spaces blur, the health of our computers has a massive impact on our productivity and overall ability to perform well at work.  Clean Out Your Computer Day, observed on the second Monday of February, is the perfect opportunity to ensure that we declutter and optimize our virtual spaces. Just as we regularly clean our homes and offices, this day underscores the importance of maintaining a streamlined, efficient computer setup. The Digital Declutter: Where to StartStarting with the basics, sift through your files and programs.
Smarty's 2023 Address Data Deep Dive: Trends, Challenges, and Breakthroughs
Arrow Icon
We recently hosted a webinar where Brent Francom and Jeffrey Duncan, two of our Product Managers, talked about the lessons we learned and the improvements we've made in 2023. Here are the highlights. When you process so many addresses, you see things. We processed 327 billion+ addresses in 2023, equating to nearly 900 million per day or over 10,000 per second. When you process that many addresses, you find many funny and interesting ones. We keep a "Wall of Shame" with funny and malformed addresses that somehow validate.
Ready to get started?