Skip to main content

A h̶i̶t̶c̶h̶h̶i̶k̶e̶r̶'s̶ software tester's guide to randomised testing - Part 2

How would test a water sac? (Wow there, calm that tester brain... I know what you are thinking, Whats it used for? Who / what uses it? how long does it need to last? Does the temperature of the water matter?  Is it single use? etc. But let's assume a generic hiking or camping water sac for now) I'm guessing one of your suggestions includes filling it with water, shaking it a bit and checking for leaks.

Seems kind of obvious right? but when it comes to software, we often do away with old-fashioned techniques such as filling something up and looking at it. Where's the machine learning test algorithm? Call this a BDD scenario? Can Selenium check for H₂0? I have to run this past the B.A...

Image result for water leaking
This is your software.

We can treat randomly generated test data and inputs in much the same way as water. Data files or other inputs like user interactions are the ever-moving parts of our applications. Think about it, the code is entirely static - it's the state or data that is changing. This contradicts the commonly held notion that the code is like a set of complicated cogs churning away until they click into place on the answer.


If your app processes data files, JSON / XML feeds or some other kind of prescribed format of inputs - create one yourself, don't just rely on the examples a Business Analyst or Product Owner has given you. Some hand rolled examples will probably be essential for smoking out bugs. But a large set of randomly generated data will probably also flush out some more. Much as you could easily detect the wet patches from a leak, you can often check easily for where your randomised data causes problems in your application.

With one client I created a large spreadsheet that included randomised data for a subset of the data fields. The generated data all matched the documented specification. Despite essentially being garbage, the data had valid relationships, text values and numbers. I imported this data into the system and looked at the user interface. What did I see? A sea of red! It turned out that the UI validation did not match the spec - in several places. Ad hoc testing had previously only found the more obvious validation mistakes.

The real smarts here probably isn't the generated data file, though that made it easier to do this sort of analysis in bulk on a complicated app full of different data types and calculations. The clever bit here is: using the app to help check itself. The data fields that allow negative fields as per the spec, were highlighted in red in the UI when negative values were imported from our file. This made finding the inconsistencies in the validation easy. The random data helped us to try out things we might never have managed to think up for ourselves.

The same goes for a complicated series of user interactions. Let's say the user works through a series screens as they buy or choose a product. Each screen has options that can take you to an array of different options. (The same principle applies to a complicated series of API interactions.). Using a set of BDD scenarios with data tables isn't going to check many of the routes users are likely to follow.

Why not make random choices from valid options (you could also include invalid ones) and see what happens. You don't have to know in advance what needs to happen exactly, just think of some heuristics. For example, If you get a 404 that's probably a bug - take a closer look. You don't even need to check the UI for that error you could check in the applications log. (Especially useful if it tries to hide the problem from the user with a helpful message / incorrect response code.)

A simple script to pick random values from a pull-down menu to reach the next screen and repeat can run in an infinite loop between each code check-in. Over and Over. Ever vigilant for Javascript errors, error response codes, slow pages etc. Let the machine do the grunt work. Save the smart and detailed investigation for people.

Comments

Popular posts from this blog

The gamification of Software Testing

A while back, I sat in on a planning meeting. Many planning meetings slide awkwardly into a sort of ad-hoc technical analysis discussion, and this was no exception. With a little prompting, the team started to draw up what they wanted to build on a whiteboard.

The picture spoke its thousand words, and I could feel that the team now understood what needed to be done. The right questions were being asked, and initial development guesstimates were approaching common sense levels.

The discussion came around to testing, skipping over how they might test the feature, the team focused immediately on how long testing would take.

When probed as to how the testing would be performed? How we might find out what the team did wrong? Confused faces stared back at me. During our ensuing chat, I realised that they had been using BDD scenarios [only] as a metric of what testing needs to be done and when they are ready to ship. (Now I knew why I was hired to help)



There is nothing wrong with checking t…

A h̶i̶t̶c̶h̶h̶i̶k̶e̶r̶'s̶ software tester's guide to randomised testing - Part 1

Mostly Harmless, I've talked and written about randomisation as a technique in software testing several times over the last few years. It's great to see people's eyes light up when they grok the concept and its potential. 
The idea that they can create random test data on the fly and pour this into the app step back and see what happens is exciting to people looking to find new blockers on their apps path to reliability.
But it's not long before a cloud appears in their sunny demeanour and they start to conceive of the possible pitfalls. Here are a few tips on how to avert the common apparent blockers. (Part 1) Problem: I've created loads of random numbers as input data, but how will I know the answer the software returns, is correct? - Do I have to re-implement the whole app logic in my test code?
Do you remember going to the fun-fair as a kid? Or maybe you recall taking your kids now as an adult? If so then you no doubt are familiar with the height restriction -…

How did you find that bug? Are we sitting comfortably, then I'll begin.

How did you find that bug? - They asked with a sort of puzzled "he dun't thunk like uz" look on their faces. An expression that suggested they were unsure whether to commend the discovery or gather their pitchforks and organise a well overdue witch burning.

Likewise, I now knew why they needed me. The team members were genuinely hard working people trying to build something new and exciting. But they lacked one thing, someone exploring & asking questions - trying to find out new things about their application. Exploring is literally a step into the unknown, and that can be uncomfortable for those not experienced in how to do it well.
So how did I find that bug? It's easy to tell a story of how I tried that particular input value because... Paragraph 3 of v4.6 of the requirements document stated that the user shall indeed on occasion X given input Y in Chrome v62 do... Or spout some other overly verbose explanation of why that broken 'scenario' came to be…