In the official document, there is only an example of the ASP.NET Core integration test using xunit.

https://docs.microsoft.com/en-us/aspnet/core/test/integration-tests

But what if you don't like xunit? Can we replace that with MSTest?

Yes. We can.

Brief steps

Uninstall xunit. Install MSTest instead.

First, clear the project structure.

Install MSTest for your test project.

Start your server in your test project.

Create a new class under the test project. Name it: BasicTests.cs.

Put the following code in your basic test:

    [TestClass]
    public class BasicTests
    {
        private readonly string _endpointUrl = $"http://localhost:{_port}"; // <- This is the server endpoint.
        private const int _port = 15999; // <- Port only for test server.
        private IHost _server; // <- This is the server object.
        private HttpClient _http; // <- We use this HTTP client to request the test server.

        [TestInitialize]
        public async Task CreateServer()
        {
            _server = Host.CreateDefaultBuilder(null)
                .ConfigureWebHostDefaults(webBuilder =>
                {
                    webBuilder.UseUrls($"http://localhost:{_port}");
                    webBuilder.UseStartup<Startup>(); // <- This Startup is from your original web project.
                }).Build();
            var handler = new HttpClientHandler()
            {
                AllowAutoRedirect = false
            };
            _http  = new HttpClient(handler);
            await _server.StartAsync(); // <- Start the server, so you can test it with the HTTP client.
        }
    }

Now when the test starts, it will auto start a new ASP.NET Core web server, using the Startup from your main web project.

Add a simple test

Insert a new function in your test class.

In that new test, you gonna request your test server. And check the result.

        [TestMethod]
        [DataRow("/")]
        [DataRow("/hOmE?aaaaaa=bbbbbb")]
        [DataRow("/hOmE/InDeX")] // <- the URL this test will try to request.
        public async Task GetHome(string url)
        {
            var response = await _http.GetAsync(_endpointUrl + url);

            response.EnsureSuccessStatusCode(); // Status Code 200-299
            Assert.AreEqual("text/html; charset=utf-8", response.Content.Headers.ContentType.ToString());

            // You can do more customized asserts here ->

        }

Now you can run your test! In Visual Studio, or execute: dotnet test under your solution folder.

Consider test clean up

After your test, you shall stop the server to prevent impacting other tests.

        [TestCleanup]
        public async Task CleanServer()
        {
            await _server.StopAsync();
            _server.Dispose();
        }

Just stop and dispose your server will finish the job.