首页 > 解决方案 > XUnit '启动' 不存在

问题描述

在我的 xunit 项目中,我收到以下错误

命名空间“TestService”中不存在类型或命名空间名称“Startup”(您是否缺少程序集引用?)[Testervice.Tests]

我通过使用将 TestService 引用添加到 Testervice.Tests

dotnet add reference ..\TestService\TestService.csproj

该引用已成功添加到测试项目中,并且在 TestService.csproj 文件中也可用。但我仍然收到错误消息。为什么我收到错误消息。任何人尝试帮助我。

标签: asp.net-core.net-coreasp.net-core-mvcxunitasp.net-core-2.1

解决方案


我不确定这会解决您的问题,但您需要创建一个继承原始 Startup.cs 的 TestStartUp 类来正确构建您的 .net 核心应用程序。示例代码如下所示。

    public class TestStartup : Startup
    {
        public TestStartup(IConfiguration configuration, IHostingEnvironment hostingEnvironment) : base(configuration, hostingEnvironment)
        {

        }
    }

希望这能解决您的问题。


推荐阅读