When creating integration tests for ASP.NET Core 10 web apps, we use the WebApplicationFactory<TEntryPoint> class. When a single ASP.NET Core web project is used as SUT, it's simple and it works:

internal class CustomWebApplicationFactory : WebApplicationFactory<Program>
{
   internal string? WebRootPath { get; private set; }

   protected override void ConfigureWebHost(IWebHostBuilder builder)
   {
      ...
   }
}

But what if I need to use 2 (or more) web apps in a single integration testing project? How can I specify which entry point class to use?

I tried WebApplicationFactory<MyAssembly.Program> but the compiler throws an error:

The type or namespace name 'Program' does not exist in the namespace 'MyAssembly' (are you missing an assembly reference?)

And no, I do have a reference to both of my web apps.

2 Replies 2

You might find this answer useful. It states:

We can often use any class from the project being tested that is sufficiently exposed to the test project.

Try to use a class that belongs to only the project you are testing as the type parameter for the WepApplicationFactory.

If I understand your problem correctly - Program class from the second assembly is not visible. If yes - than please check out this answer. Basically by default the generated Program class is internal and you need to make it visible to your test assembly (and you can use any approach from the answer, whichever you prefer).

Your Reply

By clicking “Post Your Reply”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.