.NET Core 与 NUnit 测试
.NET Core with NUnit test
我正在使用 .NET Core 并正在创建单元测试。
为此,我运行宁"dotnet new nunit -n tests"创建一个项目,第一个class测试另一个项目。
问题是:我可以 运行 使用 "dotnet test" 创建的简单代码,但我无法编码,因为我收到 'could not be found NUnit' 错误。
PS.: 我正在使用 Visual Studio Code(最新版本)。
我的.csproj:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="nunit" Version="3.11.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.11.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
</ItemGroup>
</Project>
错误:
The type or namespace name 'NUnit' could not be found (are you missing a using directive or an assembly reference?)
我使用 Visual Studio 2017(不是 Visual Studio 代码)解决了这个问题。最好构建一个 Microsoft 解决方案。
编辑:如果您使用的是Visual Studio(完整版),您可以更好地查看解决方案、项目和参考资料。
如果您正在使用 Visual Studio 代码并包含新的 class 或文件,则引用不会自动添加到您的项目文件 (.csproj) 中。也许有其他方法可以做到这一点,但目前,我只使用完整版本。
我也运行关注这个问题,也很困惑。事实证明问题出在解决方案上,而不是创建的 dotnet new nunit
项目。
解决方案是自动包含子目录并尝试将其构建为源代码。在解决方案中右键新建测试项目,选择"Exclude from Project"即可排除该目录。重建,错误消失。
我正在使用 .NET Core 并正在创建单元测试。
为此,我运行宁"dotnet new nunit -n tests"创建一个项目,第一个class测试另一个项目。
问题是:我可以 运行 使用 "dotnet test" 创建的简单代码,但我无法编码,因为我收到 'could not be found NUnit' 错误。
PS.: 我正在使用 Visual Studio Code(最新版本)。
我的.csproj:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="nunit" Version="3.11.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.11.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
</ItemGroup>
</Project>
错误:
The type or namespace name 'NUnit' could not be found (are you missing a using directive or an assembly reference?)
我使用 Visual Studio 2017(不是 Visual Studio 代码)解决了这个问题。最好构建一个 Microsoft 解决方案。
编辑:如果您使用的是Visual Studio(完整版),您可以更好地查看解决方案、项目和参考资料。
如果您正在使用 Visual Studio 代码并包含新的 class 或文件,则引用不会自动添加到您的项目文件 (.csproj) 中。也许有其他方法可以做到这一点,但目前,我只使用完整版本。
我也运行关注这个问题,也很困惑。事实证明问题出在解决方案上,而不是创建的 dotnet new nunit
项目。
解决方案是自动包含子目录并尝试将其构建为源代码。在解决方案中右键新建测试项目,选择"Exclude from Project"即可排除该目录。重建,错误消失。