Home > Software design >  Testing NUnit Startup Azure Function
Testing NUnit Startup Azure Function

Time:05-13

I want to put Unit Test to this class with NUnit, how do I do it?

using Microsoft.Azure.Functions.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection;
using Universal.DataTransferNCFDGII.Function.Services;

[assembly: FunctionsStartup(typeof(Universal.DataTransferNCFDGII.Function.Startup))]

namespace Universal.DataTransferNCFDGII.Function
{
    public class Startup : FunctionsStartup
    {
        public override void Configure(IFunctionsHostBuilder builder)
        {
            builder.Services.AddSingleton<IInsertData, InsertData>();
        }
    }
}

CodePudding user response:

Generally you do not test classes and methods Startup and Configure as there is no real logic of yours in need of testing. You would just be testing that the dependency injection setup works and that is not your code. It is a good practice while writing tests to remember to only test your code, not third party or .NET libraries. It would be better to cover this with an integration test, rather than unit test.

If you are concerned with no test for this class and method impacting your code coverage, you can just put the ExcludeFromCodeCoverage attribute on your method or class, like this:

[ExcludeFromCodeCoverage]
public override void Configure(IFunctionsHostBuilder builder)
  • Related