title: ASP.NET Core Testing - No method 'public static IHostBuilder CreateHostBuilder(string[] args)
body: <p>I'm trying to setup my application in tests and use in <code>Startup's</code> <code>Configure</code> method <code>context.Database.EnsureCreated()</code> and expecting <code>Sqlite</code> file appear in <code>Test's</code> bin folder</p>
  
  <p>Here's my code:</p>
  
  <pre><code>using Microsoft.AspNetCore.Mvc.Testing;
  using System.Threading.Tasks;
  using Xunit;
  
  namespace MyApp.Tests
  {
      public class UnitTest1 : IClassFixture&lt;CustomWebApplicationFactory&lt;FakeStartup&gt;&gt;
      {
          private readonly CustomWebApplicationFactory&lt;FakeStartup&gt; _factory;
  
          public UnitTest1(CustomWebApplicationFactory&lt;FakeStartup&gt; factory)
          {
              _factory = factory;
          }
  
          [Fact]
          public async Task Test1()
          {
              // Arrange
              var client = _factory.CreateClient();
  
              // Act
              var response = await client.GetAsync("https://localhost:5001/");
  
              // Assert
              response.EnsureSuccessStatusCode(); // Status Code 200-299
              Assert.Equal("text/html; charset=utf-8", response.Content.Headers.ContentType.ToString());
          }
      }
  }
  </code></pre>
  
  <p>Which is using WebAppFactory:</p>
  
  <pre><code>using MyApp.Tests;
  using Microsoft.AspNetCore.Hosting;
  using Microsoft.AspNetCore.Mvc.Testing;
  
  public class CustomWebApplicationFactory&lt;TStartup&gt; : WebApplicationFactory&lt;TStartup&gt; where TStartup : class
  {
      protected override void ConfigureWebHost(IWebHostBuilder builder)
      {
          builder.UseStartup&lt;FakeStartup&gt;();
      }
  }
  </code></pre>
  
  <p>Where FakeStartup is:</p>
  
  <pre><code>using MyApp.Database;
  using Microsoft.AspNetCore.Builder;
  using Microsoft.AspNetCore.Hosting;
  using Microsoft.EntityFrameworkCore;
  using Microsoft.Extensions.Configuration;
  using Microsoft.Extensions.DependencyInjection;
  using System;
  
  namespace MyApp.Tests
  {
      public class FakeStartup
      {
          public FakeStartup(IConfiguration configuration)
          {
              Configuration = configuration;
          }
  
          public IConfiguration Configuration { get; }
  
          public void ConfigureServices(IServiceCollection services)
          {            
              services.AddControllers();
  
              services.AddDbContext&lt;Context&gt;(x =&gt; x.UseSqlite($"filename={Guid.NewGuid():N}.db"));
  
              services.AddSwaggerGen(c =&gt;
              {
                  c.SwaggerDoc("v1", new OpenApiInfo { Title = "Test API", Version = "v1" });
              });
          }
      }
  
      public static void Configure(IApplicationBuilder app, IWebHostEnvironment env, Context context)
      {
          context.Database.EnsureDeleted();
          context.Database.EnsureCreated();
  
          app.UseSwagger();
          app.UseSwaggerUI(c =&gt;
          {
              c.SwaggerEndpoint("/swagger/v1/swagger.json", "Test API v1");
              c.RoutePrefix = string.Empty;
          });
  
          if (env.IsDevelopment())
          {
              app.UseDeveloperExceptionPage();
          }
  
          app.UseForwardedHeaders(new ForwardedHeadersOptions
          {
              ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
          });
  
          app.UseAuthentication();
  
          app.UseCors(x =&gt;
          {
              x.AllowAnyOrigin();
              x.AllowAnyMethod();
              x.AllowAnyHeader();
          });
  
          app.UseHttpsRedirection();
  
          app.UseRouting();
  
          app.UseAuthorization();
  
          app.UseEndpoints(endpoints =&gt;
          {
              endpoints.MapControllers();
          });
      }
  }
  </code></pre>
  
  <p>Here's problem</p>
  
  <pre><code>  Message: 
      System.InvalidOperationException : No method 'public static IHostBuilder CreateHostBuilder(string[] args)' or 'public static IWebHostBuilder CreateWebHostBuilder(string[] args)' found on 'AutoGeneratedProgram'. Alternatively, WebApplicationFactory`1 can be extended and 'CreateHostBuilder' or 'CreateWebHostBuilder' can be overridden to provide your own instance.
    Stack Trace: 
      WebApplicationFactory`1.CreateWebHostBuilder()
      WebApplicationFactory`1.EnsureServer()
      WebApplicationFactory`1.CreateDefaultClient(DelegatingHandler[] handlers)
      WebApplicationFactory`1.CreateDefaultClient(Uri baseAddress, DelegatingHandler[] handlers)
      WebApplicationFactory`1.CreateClient(WebApplicationFactoryClientOptions options)
      WebApplicationFactory`1.CreateClient()
      UnitTest1.Test1() line 20
      --- End of stack trace from previous location where exception was thrown
  </code></pre>
  
  <p>What may be causing this? thanks in advance</p>