Skip to main content

Testing Functions

The Developer Portal includes a built-in test runner for testing functions before deploying them to production.

Test Runner​

Access the test runner from any function's edit page.

Features​

FeatureDescription
Custom input dataDefine JSON test data
Method selectionChoose HTTP method (for HTTP functions)
Query parametersAdd query string parameters
User contextTest as different users
Real-time executionSee results immediately
Log viewingView console output
Saved test inputsSave and reuse test scenarios

Running a Test​

  1. Open your function in the Developer Portal
  2. Click Test or open the test panel
  3. Configure your test input:
    • Enter JSON data in the Body field
    • Add query parameters if needed
    • Select HTTP method (HTTP functions)
  4. Click Run
  5. View results and logs

Test Input Configuration​

Request Body​

Enter JSON data that simulates the request body:

{
"orderId": "order-123",
"items": [
{ "productId": "prod-1", "quantity": 2 },
{ "productId": "prod-2", "quantity": 1 }
],
"customerId": "cust-456"
}

Query Parameters​

Add query parameters for HTTP function tests:

ParameterValue
page1
limit10
filteractive

HTTP Method​

For HTTP functions, select the method to test:

  • GET
  • POST

User Context​

The Current User Context control in the sidebar lets you test how your function behaves for different users. This is a global setting shared across REST Explorer, Data Explorer, and Function Testing.

OptionDescription
System UserFull access with "Skip roles" enabled (default)
UnauthenticatedTest as anonymous user
API UsersSelect a specific user or service account from your API

Testing Permissions​

OptionDescription
Skip Security PolicyBypass row-level access control
Skip RolesIgnore role-based permissions (auto-enabled for System user)

Use these options to test function logic separately from access control.

Viewing Results​

Output​

For HTTP functions, the res object you set appears in the Output section:

{
"success": true,
"processedItems": 3,
"total": 149.97
}

For trigger functions, you'll see the modified item that will be saved.

Logs​

Console output appears in the Logs section:

[INFO] 0ms - Processing order: order-123
[INFO] 15ms - Found 3 items
[INFO] 45ms - Calculated total: 149.97
[WARN] 46ms - Customer has pending balance

Each log entry shows:

  • Severity level (INFO, WARN, ERROR)
  • Milliseconds from execution start
  • Message

Validation Errors​

If validationErrors has any items, you'll see a 400 response with the errors:

["Invalid order: no items provided"]

Runtime Errors​

Runtime errors (undefined variables, failed external calls, etc.) are shown in the logs but not in the response body. This matches production behavior where internal errors are not exposed to clients.

Execution Time​

View total execution time in milliseconds to identify performance issues.

Saved Test Inputs​

Save test configurations for reuse and regression testing.

Saving a Test Input​

  1. Configure your test (body, query params, method)
  2. Click Save Test Input
  3. Enter a descriptive name (e.g., "Valid order with 3 items")
  4. Click Save

Managing Saved Inputs​

ActionDescription
LoadApply saved input to current test
UpdateUpdate saved input with current values
RenameChange the saved input name
DeleteRemove saved input

Best Practices for Saved Inputs​

Create saved inputs for:

  • Happy path — Valid data that should succeed
  • Edge cases — Boundary conditions (empty arrays, max values)
  • Error cases — Invalid data that should fail gracefully
  • Permission scenarios — Different user roles

Testing Strategies​

Unit Testing Approach​

Test individual functions in isolation:

  1. Test with minimal valid input
  2. Test with complete valid input
  3. Test with invalid input
  4. Test edge cases

Integration Testing​

Test functions that interact with data:

  1. Create test data in collections
  2. Run function
  3. Verify data changes
  4. Clean up test data

Regression Testing​

Use saved test inputs to catch regressions:

  1. Create comprehensive saved inputs during development
  2. Run all saved inputs after changes
  3. Verify outputs match expectations

Debugging Tips​

Add Logging​

Insert log() statements to trace execution:

// Trigger functions
log('Processing item:', item.id);
log('Method:', req.method);

// HTTP functions
log('Request body:', JSON.stringify(req.bodyJson));
log('Calculated result:', result);

Check Variable Values​

Log intermediate values to find issues:

const filtered = items.filter(i => i.active);
log('Filtered items count:', filtered.length);

const total = filtered.reduce((sum, i) => sum + i.price, 0);
log('Total before tax:', total);

Isolate Problems​

Test components separately:

// Test external API call alone
const response = await fetch(externalUrl);
log('External API status:', response.status);
log('External API response:', await response.text());

Test Permissions Separately​

  1. First test with Skip Security Policy and Skip Roles enabled
  2. Verify the function logic works
  3. Then test with actual permissions
  4. Fix any access control issues

Common Issues​

Function Times Out​

  • Check for infinite loops
  • Reduce external API calls
  • Use parallel requests where possible
  • Increase timeout limit if needed

Unexpected Results​

  • Log intermediate values
  • Check input data format
  • Verify external API responses
  • Check for async/await issues

Permission Denied​

  • Test with Skip Security Policy/Roles first
  • Verify service account permissions
  • Check role assignments
  • Review security policy paths