Stuck Needle Testing

Testing with the expectation of a static value is a great way to tell if things are working at a high level. But how would you tell if you’re getting the current static value, and not a cached one? In a sense, how would you tell if the “needle is stuck”?

What’s the Needle?

Let’s say you have a mechanical engine. It’s working at a certain rate, all the time, rotating a shaft.

Let’s also say you have a tachometer on it that reads how much work is being done, in rotations per minute.

The needle in this case is the physical needle in the tachometer, telling you how hard your engine is working.

Is It Stuck?

If you need to tell whether your tachometer is actually giving you an accurate readout, you have two options: change what the engine is doing, or change something about the tachometer.

I bet in some circumstances it would be ill-advised to change the speed of the engine.

For a car, yes it’s fine. Just give it some gas. Zoom zoom. But for something where the engine must work at a certain speed, it’s probably not fine.

So I’ll assume that fooling with the engine itself isn’t an option.

This leaves us with the tach itself. If your engine is working at, let’s say, 10,000 rotations per minute, then what do you do to tell if the readout is accurate?

Simple. Move the needle.

If the needle bounces right back to 10K, then you know it’s a good readout. If not, something’s wrong.

Maybe the needle’s rusted in place. Maybe it’s not getting voltage and is just sitting there, not going back down to 0. Maybe it’s not calibrated correctly.

I don’t know.

But what I do know is, you can’t trust this readout, and had you not performed this test, you may have gone on blissfully assuming that the engine was operating at the desired level. Until it wasn’t.

How’s This Apply to Software?

I’m working on a test right now, where we have devices we need to get static data from. Each device has its own hardcoded value.

From a webpage, we can request the data from the device and it gives us an answer. For these static devices, the value should always be the same.

But if we always assume that the value on the screen is correct, because it’s the same as last time, then we may miss the times where the data’s not actually being updated.

So we need to move the needle.

How Would You “Move the Needle” Now?

Simple. Use Javascript!

For this case, we have an element on the screen–a span–that holds that information.

We can use Javascript to change the text of that element to some junk value, like 1234567. Then, we wait until the value is updated to the actual static data.

If, after a set amount of time, the value doesn’t update, then it means our needle was stuck, and we need to figure out why.

Here’s the snippet of Javascript:

var element = document.evaluate(
   "//span[@id='staticdata']", 
   document, 
   null, 
   XPathResult.FIRST_ORDERED_NODE_TYPE, 
   null 
   ).singleNodeValue;

if (element != null) {
   element.setAttribute('innerHTML', '1234567');
}

Then later, we check the “staticdata” element for an update, to be at the expected value. If enough time’s passed, and we still have ‘1234567’, then the device has some splainin’ to do.

Maybe the device isn’t communicating properly. Maybe the webpage isn’t sending out the request. Maybe something else in the chain isn’t passing data around right. It could be anything. But we’d never know if we didn’t tweak the value first.

Where Does This Apply For You?

Hey hopefully I didn’t scare you with this post, but yeah I’m gonna ask the question: Do you have places where you’re assuming a static value is being updated every time?

Would tweaking values like this help you identify bugs sooner?

Share below! And let me know if this helps.

Thanks for reading–Fritz

Advertisements

5 thoughts on “Stuck Needle Testing

  1. Nice concept. Here’s an example from my experience I can think of – when I’m running more than one test without completely resetting the state of the system under test, I will make sure I vary the test data so that the data changes each time in all the relevant fields I want to check. Then I’ll catch the case where the field doesn’t get updated at all.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s