Open baharedankoyuncu opened 3 years ago
Hello @baharedankoyuncu , Recently I've been able to run integration tests on Azure Functions using HostBuilder and, combined with testenvironment-docker package, now we have full integration tests running on CI/CD pipeline. Hope this sample code helps you as a guide
/// It is not possible to configure running ConfigureWebHost when running Azure Functions.
/// Following statements throw exception:
/// var host = new HostBuilder().ConfigureWebHost(x => x.UseStartup<Startup>());
/// var host = new HostBuilder().ConfigureWebHost(x => x.UseTestServer());
var startup = new Startup();
var builder = new HostBuilder()
.ConfigureAppConfiguration((context, config) =>
{
config
.AddInMemoryCollection(new[] {
new KeyValuePair<string, string>("AzureWebJobsStorage", "UseDevelopmentStorage=true"),
new KeyValuePair<string, string>("FUNCTIONS_WORKER_RUNTIME","dotnet"),
[...]
})
.AddEnvironmentVariables();
})
.ConfigureWebJobs(startup.Configure);
var host = builder.Build();
await host.StartAsync();
var function1 = new Function1(host.Services.GetRequiredService<ILogger<Function1>>(),
[...] );
await function1.Run([...]);
Hi @dgvives,
Interesting approach, however I've no experience with docker in regards to your setup. I have tried to simply spin up a ProcessStartInfo
using the Azure Functions Tools and pointing to my function but this isn't elegant in anyway when considering a CI/CD pipeline. I was hoping there would be something similar to the TestServer in ASP.NET Core.
You may succeed adding test server and webclient to hostbuilder, however I didn't manage to so instead of running http requests in webclient I just called function procedures, and it works.
Provided sample doesn't utilize docker
Thanks, I see and understand but I was hoping there would be something "official" and user friendly.
@apawast is there any input from MS on this?
Any updates on this?
Integration testing support with TestServer for Azure Functions would be a huge improvement to get our testing strategy on par with regular ASP.NET Core Web API's.
Any update on this?
Hi 👋
I hope I've come to the right repo.
Are there any plans to support a "Test Server" similar to the one in ASP.NET Core? I've read quite a few posts, most which are dated, on how to glue something together which doesn't work.
I was wondering if there are any plans to support this or if it's already a feature being tracked?