azure-functions-test
Runs Azure Functions locally using Azure Functions Core Tools v4 (`func start`), Azurite storage emulation, and framework-native unit tests for handler code (.NET isolated worker model, Node.js v4, Python v2). Covers HTTP, queue, and timer trigger testing, admin-endpoint invocation for non-HTTP triggers, and binding verification via local.settings.json. Use when testing Azure Functions before deployment, reproducing trigger behaviour without live Azure services, or gating function handler logic in CI.
azure-functions-test
Overview
Azure Functions Core Tools v4 (func.exe) provides a local runtime that mirrors the Functions host on Azure. Per learn.microsoft.com/azure/azure-functions/functions-run-local, func start starts all triggers in the project directory and outputs the URL of every HTTP-triggered function. Azurite emulates Blob, Queue, and Table Storage locally so queue and timer triggers can be exercised without a live storage account.
Nearest neighbours and how this skill differs:
When to use
Install
# macOS
brew tap azure/functions
brew install azure-functions-core-tools@4
# Ubuntu/Debian (see full APT steps at learn.microsoft.com/azure/azure-functions/functions-run-local#install-the-azure-functions-core-tools)
sudo apt-get install azure-functions-core-tools-4
# Windows: download the MSI from
# https://go.microsoft.com/fwlink/?linkid=2174087 (64-bit) per the Core Tools docsVerify:
func --version # must be 4.xInstall Azurite via npm, per learn.microsoft.com/azure/storage/common/storage-install-azurite:
npm install -g azuriteProject initialisation
# .NET isolated worker model (recommended; in-process support ends 2026-11-10
# per learn.microsoft.com/azure/azure-functions/dotnet-isolated-in-process-differences)
func init MyApp --worker-runtime dotnet-isolated
# Node.js (v4 programming model)
func init MyApp --worker-runtime javascript --model V4
# Python (v2 programming model)
func init MyApp --worker-runtime python --model V2
# Add a trigger template
func new --template "Http Trigger" --name HttpExample
func new --template "Azure Queue Storage Trigger" --name QueueExample
func new --template "Timer trigger" --name TimerExamplelocal.settings.json
Per learn.microsoft.com/azure/azure-functions/functions-develop-local, local.settings.json holds app settings used only when running locally. Set AzureWebJobsStorage to UseDevelopmentStorage=true to route storage triggers to Azurite:
{
"IsEncrypted": false,
"Values": {
"FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated",
"AzureWebJobsStorage": "UseDevelopmentStorage=true"
}
}Never commit local.settings.json to source control; it may contain connection strings.
Start Azurite
Azurite emulates Blob (port 10000), Queue (port 10001), and Table (port 10002) per learn.microsoft.com/azure/storage/common/storage-install-azurite. Start it before func start:
azurite --silent --location ./azurite-dataFor Docker:
docker run -p 10000:10000 -p 10001:10001 -p 10002:10002 \
mcr.microsoft.com/azure-storage/azuriteStart the local Functions host
From the project root, per learn.microsoft.com/azure/azure-functions/functions-run-local#start-the-functions-runtime:
func startOutput includes HTTP trigger URLs, e.g.:
Http Function HttpExample: http://localhost:7071/api/HttpExampleBy default, HTTP authorization is not enforced locally (all requests are treated as authLevel = "anonymous"). Pass --enableAuth to require authorization during local testing.
Testing triggers
HTTP trigger
# GET
curl http://localhost:7071/api/HttpExample?name=World
# POST
curl --request POST http://localhost:7071/api/HttpExample \
--data '{"name":"World"}'Non-HTTP triggers (admin endpoint)
Per learn.microsoft.com/azure/azure-functions/functions-manually-run-non-http, non-HTTP triggers can be fired via the admin endpoint. Authorization is bypassed locally:
# Queue trigger named QueueExample
curl --request POST \
-H "Content-Type: application/json" \
--data '{"input":"sample queue payload"}' \
http://localhost:7071/admin/functions/QueueExample
# Timer trigger named TimerExample (empty input is valid)
curl --request POST \
-H "Content-Type: application/json" \
--data '{}' \
http://localhost:7071/admin/functions/TimerExampleThe endpoint returns HTTP 202 (Accepted) on success.
Unit-testing handlers
Testing handler code directly avoids the overhead of a running host. The approach differs by language.
.NET isolated worker model
The .NET isolated worker model runs function code in a separate worker process from the Functions host, per learn.microsoft.com/azure/azure-functions/dotnet-isolated-in-process-differences. The core packages are Microsoft.Azure.Functions.Worker and Microsoft.Azure.Functions.Worker.Sdk. HTTP triggers use HttpRequestData / HttpResponseData (not HttpRequest/IActionResult) unless ASP.NET Core integration is enabled.
Because handler classes can use dependency injection, extract service dependencies behind interfaces and substitute test doubles. The FunctionContext can be mocked with any standard mock library.
// Handler under test
public class HttpExample
{
[Function("HttpExample")]
public HttpResponseData Run(
[HttpTrigger(AuthorizationLevel.Function, "get", "post")] HttpRequestData req,
FunctionContext context)
{
var response = req.CreateResponse(HttpStatusCode.OK);
response.WriteString("Hello from Azure Functions");
return response;
}
}
// xUnit test - construct HttpRequestData via a mock FunctionContext
// (use Moq, NSubstitute, or similar for FunctionContext and HttpRequestData)
[Fact]
public async Task Run_ReturnsOk()
{
var context = new Mock<FunctionContext>();
var request = CreateMockHttpRequest(context.Object, HttpMethod.Get);
var function = new HttpExample();
var response = function.Run(request, context.Object);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
}Node.js (v4 programming model)
// handler.js
const { app } = require('@azure/functions');
app.http('HttpExample', {
methods: ['GET', 'POST'],
authLevel: 'anonymous',
handler: async (request, context) => {
const name = request.query.get('name') || 'World';
return { body: `Hello, ${name}!` };
},
});
// handler.test.js (Jest)
const { handler } = require('./handler');
test('returns greeting', async () => {
const req = { query: new URLSearchParams('name=Test'), text: async () => '' };
const ctx = { log: jest.fn() };
const res = await handler(req, ctx);
expect(res.body).toBe('Hello, Test!');
});Python (v2 programming model)
# function_app.py
import azure.functions as func
app = func.FunctionApp()
@app.route(route="HttpExample")
def http_example(req: func.HttpRequest) -> func.HttpResponse:
name = req.params.get('name', 'World')
return func.HttpResponse(f"Hello, {name}!")
# test_function_app.py (pytest)
import azure.functions as func
from function_app import http_example
def test_http_example():
req = func.HttpRequest(
method='GET',
url='/api/HttpExample',
params={'name': 'Test'},
body=b''
)
resp = http_example(req)
assert resp.status_code == 200
assert 'Test' in resp.get_body().decode()CI integration
jobs:
azure-functions-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Core Tools
run: |
curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg
sudo mv microsoft.gpg /etc/apt/trusted.gpg.d/microsoft.gpg
sudo sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-ubuntu-$(lsb_release -cs)-prod $(lsb_release -cs) main" > /etc/apt/sources.list.d/dotnetdev.list'
sudo apt-get update && sudo apt-get install -y azure-functions-core-tools-4
- name: Start Azurite
run: npx azurite --silent &
- name: Run unit tests
run: dotnet test # or: pytest / npm testAnti-patterns
| Anti-pattern | Why it fails | Fix |
|---|---|---|
| Skip Azurite for queue/timer triggers | Queue and storage triggers require AzureWebJobsStorage; without it func start errors | Start Azurite and set "AzureWebJobsStorage": "UseDevelopmentStorage=true" in local.settings.json |
| Use in-process model for new projects | Support for in-process model ends 2026-11-10 per learn.microsoft.com/azure/azure-functions/dotnet-isolated-in-process-differences | Use --worker-runtime dotnet-isolated |
| Hard-code connection strings in code | Secrets leak to source control | Use local.settings.json Values array; it is git-ignored by default |
Call admin endpoint without Content-Type: application/json | Host rejects the request | Always include Content-Type: application/json header and {"input":"..."} body |
Commit local.settings.json | Contains secrets | Verify .gitignore excludes it; use func settings to sync with Azure app settings |
Use func host start for Core Tools v4 | Command removed in v4; it was v1.x syntax per Core Tools docs | Use func start |