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
| Feature | Description |
|---|---|
| Custom input data | Define JSON test data |
| Method selection | Choose HTTP method (for invocable functions) |
| Query parameters | Add query string parameters |
| User context | Test as different users |
| Real-time execution | See results immediately |
| Log viewing | View console output |
| Saved test inputs | Save and reuse test scenarios |
Running a Test
- Open your function in the Developer Portal
- Click Test or open the test panel
- Configure your test input:
- Enter JSON data in the Body field
- Add query parameters if needed
- Select HTTP method (invocable functions)
- Click Run
- 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 invocable function tests:
| Parameter | Value |
|---|---|
page | 1 |
limit | 10 |
filter | active |
HTTP Method
For invocable functions, select the method to test:
- GET
- POST
- PUT
- DELETE
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.
| Option | Description |
|---|---|
| System User | Full access with "Skip roles" enabled (default) |
| Unauthenticated | Test as anonymous user |
| API Users | Select a specific user or service account from your API |
Testing Permissions
| Option | Description |
|---|---|
| Skip Security Policy | Bypass row-level access control |
| Skip Roles | Ignore role-based permissions (auto-enabled for System user) |
Use these options to test function logic separately from access control.
Viewing Results
Output
For invocable 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
- Configure your test (body, query params, method)
- Click Save Test Input
- Enter a descriptive name (e.g., "Valid order with 3 items")
- Click Save
Managing Saved Inputs
| Action | Description |
|---|---|
| Load | Apply saved input to current test |
| Update | Update saved input with current values |
| Rename | Change the saved input name |
| Delete | Remove 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:
- Test with minimal valid input
- Test with complete valid input
- Test with invalid input
- Test edge cases
Integration Testing
Test functions that interact with data:
- Create test data in collections
- Run function
- Verify data changes
- Clean up test data
Regression Testing
Use saved test inputs to catch regressions:
- Create comprehensive saved inputs during development
- Run all saved inputs after changes
- 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);
// Invocable 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
- First test with Skip Security Policy and Skip Roles enabled
- Verify the function logic works
- Then test with actual permissions
- 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