diff --git a/src/Microsoft.AspNetCore.Mvc.Testing/WebApplicationFactory.cs b/src/Microsoft.AspNetCore.Mvc.Testing/WebApplicationFactory.cs
index 910db78d92..f1edf8fc04 100644
--- a/src/Microsoft.AspNetCore.Mvc.Testing/WebApplicationFactory.cs
+++ b/src/Microsoft.AspNetCore.Mvc.Testing/WebApplicationFactory.cs
@@ -243,13 +243,22 @@ namespace Microsoft.AspNetCore.Mvc.Testing
/// array as arguments.
///
/// A instance.
- protected virtual IWebHostBuilder CreateWebHostBuilder() =>
- WebHostBuilderFactory.CreateFromTypesAssemblyEntryPoint(Array.Empty()) ??
- throw new InvalidOperationException(Resources.FormatMissingCreateWebHostBuilderMethod(
- nameof(IWebHostBuilder),
- typeof(TEntryPoint).Assembly.EntryPoint.DeclaringType.FullName,
- typeof(WebApplicationFactory).Name,
- nameof(CreateWebHostBuilder)));
+ protected virtual IWebHostBuilder CreateWebHostBuilder()
+ {
+ var builder = WebHostBuilderFactory.CreateFromTypesAssemblyEntryPoint(Array.Empty());
+ if (builder == null)
+ {
+ throw new InvalidOperationException(Resources.FormatMissingCreateWebHostBuilderMethod(
+ nameof(IWebHostBuilder),
+ typeof(TEntryPoint).Assembly.EntryPoint.DeclaringType.FullName,
+ typeof(WebApplicationFactory).Name,
+ nameof(CreateWebHostBuilder)));
+ }
+ else
+ {
+ return builder.UseEnvironment("Development");
+ }
+ }
///
/// Creates the with the bootstrapped application in .