0
votes

What is the best approach for integration testing an Azure TimerTrigger Function?

I have an Azure Function that copies data from an Oracle table to Azure SQL table and sends an email via SendGrid. Here is the pseudo code:

public static void Run(TimerInfo myTimer, ILogger log)
{
    Fecth_Data_From_Oracle_table()
    Insert_Data_To_AzureSQL_table()
    Send_StatusEmail_Via_SendGrid()
}

As seen the Function doesn't return anything, so how would I approach Integration Testing this function?

Do I modify the return type to something like Task<IActionResult>, but then I am modifying some already running code and returning some HTTP codes based on results from the methods?

Do I just call the timer trigger function from Visual Studio with the api key and HttpClient class f.x. GET https://myfunc01.azurewebsites.net/admin/functions/TimerTriggereFunc?code={key} and assert on its return value? (This requires that the Function returns something.)

Jeff Holan has examples of integration testing an Azure Function locally by using the System.Diagnostics.Process class to start and stop the .NET Core CLI (dotnet.exe), which in turn starts the Azure Functions host through the func.dll, but this seems overly complicated. Is it a wrong approach to integration test the Azure Function where it is hosted in Azure or is it a must to test it locally?

I can't seem to find clear guidelines around this.

1
What's the aim of your tests? For example, if you want to ensure that your "Insert_Data_To_AzureSQL_table" function has run successfully, then you should check that it's inserted the expected data in your database. - Amicable

1 Answers

-1
votes

If you want to test your timer trigger function, you can create Application Insights for your it when you create your function on azure portal. It can help you monitor your azure function and you can use 'log.LogInformation' to print anything you want in your timer trigger function. Then you can click "Monitor" button in your function and see the log of it. If you want to know more information of your function, you can click "Live app metrics" button. enter image description here