BlogFileMaker

Test Data Generator

By May 12, 2015 6 Comments

Manual Entry of Test Data Discourages Testing

When testing the functionality of a solution, software developers frequently have to create test records, which requires them to enter in test data. If the fields requiring a value include a name field, I’m good to go for about 5-6 records, until I exhaust the ‘first name’ supply that I seem to keep handy in my brain. If I also need to enter in address data, I’m hopeless. Pretty soon, I’m just typing in “xxx” or “asdf”. If there’s data validation in place, then I’m in real trouble.

The net effect of this manual entry is it discourages effective testing.

Custom Functions To Generate Test Data

To address this problem, I created a set of custom functions to create data for the most typical types of fields:

  • Name (first, last, full)
  • Gender
  • Phone, Fax
  • Email
  • Address (Street, City, Zip, State, Country)
  • Date (ex DOB), Time
  • SSN
  • Company
  • Notes/Comments

There’s also a custom function in there that selects a random value from a value list that you specify.

Now I’ve gotten in the habit of creating a script for each entity (table) that I have to create test data for. The script fills in all of the fields using the custom functions. I place a button to call the script on the layouts where I need it for testing, and I use the FileMaker 13 “Hide object when” feature to hide the button when the user is not a full access user.

Setting up the script takes a few minutes, but it’s well worth it, because it then becomes quick and easy to create realistic test data.

Type Of Data Supported (Not Just Contacts)

The demo file tracks contacts data, but these custom functions can be used for any type of data. For example, if you wanted to do this for creating invoice records, you could set it up like this:

  • Date – RandomDate ( 2014 ; 2015 )
  • Type – RandomValueFromValueList ( “Invoice Type” )
  • Terms – RandomValueFromValueList ( “Terms” )
  • Summary – RandomWords ( 3 ; 5 )
  • Item – RandomWords ( 1 ; 2 )
  • Quantity – RandomNumber ( 1 ; 5 ; 0 ) // random number between 1 and 5
  • Unit Price – RandomNumber ( 100 ; 300 ; -2 ) // $100 or $200 or $300
  • Tax Rate – RandomValueFromValueList ( “Tax Rate” )

Using Test Data To Stress Test A Solution

Another situation where this technique can be useful is when you need to stress test your solution, for example by creating tens or hundreds of thousands of records, to see how it performs under such large record volumes. For this purpose I created a “Create More Test Records” script that prompts the user for the number of new records to create.

Creating Context For Your Users

Users have a hard time relating to an empty system (a solution without any data in it). This can be a challenge when you are demoing new functionality that you’ve created or when a subset of users are testing the solution during the user acceptance testing (UAT) phase of a project. You can use the Test Data Generator to quickly and easily populate your solution with realistic data. Your testers will thank you!

Demo File

Take a look at the demo file I’ve put together. Click on the “Create More Test Records” button to create new, blank records, and then click on the “Use Test Values” button to fill them with test data.

Modular FileMaker

I built the demo file following the modular approach prescribed at modularfilemaker.org. It would be easy enough to simply copy the custom functions to your solution, and you’re welcome to do just that. But then you would still have to create a script that uses those functions to set the appropriate fields.

Instead you can use the “Use Test Values” script that’s included in the module. This script takes in a parameter to specify the following:

  • A list of fields to populate with test data
  • Instructions on how to populate those fields (i.e. which custom function to use for each field)
  • Whether the fields should be set for just the current record or the entire found set
  • Whether existing data should be left alone or replaced with new test data

For example, the script parameter might look like this:

# ( "fieldsAndCalcs" ;
	List (
		GetFieldName ( Contact::Name_Last ) ; 
		"RandomNameLast" ;
		
		GetFieldName ( Contact::DOB ) ; 
		"RandomDate ( 1940 ; 1990 )" ; // random date between 1940 and 1980
		
		GetFieldName ( Contact::Phone ) ;
		"RandomPhone" ;
		
		GetFieldName ( Contact::Address_Street ) ;
		"RandomStreetAddress" ;
	)
)
& # ( "target" ; "current record" )
& # ( "leaveOrReplace" ; "replace" )

You still have to create a script for the table you want to use this for, but now this script becomes a lot simpler. In fact it can consist of just this single step where you call the “Use Test Value” subscript, passing it the parameter like the one shown above:

Perform Script ["Use Test Values"; Parameter: param_from_above]

To have the parameter created for you, run the “Create Parameter” script. It will figure out the list of normal fields (i.e. no summary, calcs or globals) that are present on your current layout and then generate the parameter accordingly. The only thing left to do then is to specify which custom function you’d like to use for each field.

Caveats

The addresses that are generated using the custom functions are not real; i.e. they do no represent actual locations. So this approach won’t work if, for example, you need to test mapping functionality.

There is no custom function to generate container data, but you could use a Set Field step to simply set the text “Test” to your container field. Regardless of whether the field is optimized for images or interactive content on your layout, you will see the word “Test” in there.

The “Use Test Values” script can set data to the current found set or just the current record. To keep the script portable, I’m using the Set Field by Name script step, so that the fields can be specified indirectly. The Replace Field Contents step does not offer this option, so when the “Use Test Values” script is working with the found set, instead of just the current record, it loops through each record, so that the Set Field by Name step can be used. This makes it a bit slower, but preserves functionality that would otherwise have been lost.

How-To Video

I’ve put together a video to show you how you can use this module in your own solution.

Watch the video: Generating Random Test Data in FileMaker.

Mislav Kos

Mislav Kos

Mislav is a FileMaker developer and a Technical Solution Architect at Soliant Consulting.

6 Comments

Leave a Reply

Need to adjust your business processes quickly? We're helping clients use technology to keep their teams productive and running smoothly in these times of uncertainty. Our team can guide yours if you need help in these areas.

Talk to a Consultant