Testing FileMaker scripts systematically

Expert

Apply unit testing principles to FileMaker scripts using test scripts, assertion patterns, and a test runner to catch regressions before deployment.

What you'll learn

  • How to write a FileMaker test script for a utility function
  • How to implement an assertion pattern with a dedicated assert sub-script
  • How to build a test runner that executes all tests and reports results
  • How to test scripts that modify records using setup and teardown patterns
  • How to integrate test scripts into a pre-deployment checklist

FileMaker has no built-in test framework, but you can build one using scripts, a results table, and an assertion pattern. Each "test" is a script that calls the script under test with a known input, checks the result against the expected output, and writes a pass/fail entry to a test results table. A test runner script executes all test scripts and displays a summary.

1/3
1

Write a test script for a utility function

A test script calls the target script with a specific input and checks whether the result matches the expected value. Name test scripts with a "Test - " prefix so they are visually grouped and easy to find.

FileMaker Script
# Script: Test - Util - Format Phone Number
# Tests the "Util - Format Phone Number" utility script

Set Variable [ $passCount ; Value: 0 ]
Set Variable [ $failCount ; Value: 0 ]

# -- Test 1: standard 10-digit US number ------------------
Perform Script [ "Util - Format Phone Number" ;
  Parameter: JSONSetElement ( "{}" ; [ "phone" ; "5551234567" ; JSONString ] ; [ "format" ; "us" ; JSONString ] )
]
Set Variable [ $result ; Value: Get ( ScriptResult ) ]
If [ JSONGetElement ( $result ; "formatted" ) = "(555) 123-4567" ]
  Set Variable [ $passCount ; Value: $passCount + 1 ]
Else
  Set Variable [ $failCount ; Value: $failCount + 1 ]
  # Log failure
  Perform Script [ "Test - Record Result" ;
    Parameter: JSONSetElement ( "{}" ;
      [ "test" ; "Format 10-digit US" ; JSONString ] ;
      [ "expected" ; "(555) 123-4567" ; JSONString ] ;
      [ "actual" ; JSONGetElement ( $result ; "formatted" ) ; JSONString ] ;
      [ "passed" ; False ; JSONBoolean ]
    )
  ]
End If

# -- Test 2: empty phone number ----------------------------
Perform Script [ "Util - Format Phone Number" ;
  Parameter: JSONSetElement ( "{}" ; [ "phone" ; "" ; JSONString ] )
]
Set Variable [ $result ; Value: Get ( ScriptResult ) ]
If [ JSONGetElement ( $result ; "success" ) = "false" ]
  Set Variable [ $passCount ; Value: $passCount + 1 ]
Else
  Set Variable [ $failCount ; Value: $failCount + 1 ]
End If

Exit Script [ Text Result:
  JSONSetElement ( "{}" ;
    [ "passed" ; $passCount ; JSONNumber ] ;
    [ "failed" ; $failCount ; JSONNumber ]
  )
]

Sign in to track your progress and pick up where you left off.

Sign in to FM Dojo