.net core:集成测试:获取错误:找不到XUnitTestClassRunner.cs

问题描述 投票:1回答:1

PFB错误:

enter image description here

TestFixture设置:

public TestServerFixture()
    {
        var configuration = new ConfigurationBuilder()
                        .AddJsonFile(@"appsettings.json")
                        .Build();

        //Assembly startupAssembly = typeof(Startup).GetTypeInfo().Assembly;
        //var contentRoot = GetProjectPath(startupAssembly);

        var builder = new WebHostBuilder()
               .UseContentRoot(this.GetContentRootPath())
               .UseEnvironment("Testing").UseConfiguration(configuration)
               .UseStartup<Startup>();  // Uses Start up class from your API Host project to configure the test server

        this._testServer = new TestServer(builder);
        this.Client = this._testServer.CreateClient();
    }

测试方法:

public class SearchControllerTest : IClassFixture<TestServerFixture>
{
    private readonly TestServerFixture _fixture;

    public SearchControllerTest(TestServerFixture fixture)
    {
        _fixture = fixture;
    }

    [Fact]
    public async Task SearchData()
    {
        var response = await _fixture.Client.GetAsync("/api/SearchController/Test");

        response.EnsureSuccessStatusCode();

        var responseStrong = await response.Content.ReadAsStringAsync();

    }
}

创建客户端对象后,事件SearchData未被调用并出现上述错误。

c# .net .net-core xunit xunit.net
1个回答
0
投票

我已经通过Visual Studio中的工具菜单启用调试我的代码选项解决了这个问题。

工具 - >选项 - >调试 - >常规 - >选择启用我的代码选项

© www.soinside.com 2019 - 2024. All rights reserved.