New 42-day free trial
Smarty

Your Convey needs more focus

Smarty header pin graphic
February 7, 2014
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 icon
Subscribe Now
Read our recent posts
Patient form optimization: The $17.4 million problem
Arrow Icon
Let's start with a number that should make every hospital administrator do a double take: $17. 4 million. That’s how much the average hospital loses annually—just from denied claims due to patient misidentification. This isn’t from equipment costs, not from staffing shortages, and not even from insurance negotiations—just from keeping bad patient data. Surely, our forms aren’t that bad. (Yes, they are, and stop calling me Shirley. )But here’s the reality: According to the 2016 Ponemon Misidentification Report, 30% of hospital claims get denied, and over a third of those denials are caused by inaccurate or incomplete patient information.
The GPS adventures of a distracted developer
Arrow Icon
My name is Jeffrey Duncan, and at the pestering of Smarty’s editor, I’m writing a blog about the many adventures I’ve had in life and how address data has played a big part in them. I met my wife about eight years ago on a dating website. At the time, I lived in Provo, Utah, while she lived in Palmwoods, Australia, on the east coast of Queensland. On this dating app, I entered the area where I was interested in finding someone, about a 25-mile radius of Provo, Utah. I had no intention of leaving the valley, definitely not the state, and certainly not the country.
Improving address data quality in healthcare
Arrow Icon
Healthcare is experiencing a dramatic shift in how patient information is stored and managed. Electronic medical records (EMRs) and electronic health records (EHRs) have become the new standard, driven by two powerful forces: everyone has mobile devices and the increase in the human population. A growing problem with clean address data in EMRs and EHRsWhile EMRs and EHRs offer amazing accessibility and storage capabilities (way better than a filing cabinet), they've also exposed a critical weakness in many healthcare organizations: address data quality.

Ready to get started?