首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >防止项目作为测试项目被发现

防止项目作为测试项目被发现
EN

Stack Overflow用户
提问于 2020-05-18 07:06:51
回答 1查看 732关注 0票数 4

对于几个项目,我有一个通用的使用项目,它包含一些基本的测试类、助手类等等。项目定义如下所示:

代码语言:javascript
运行
复制
<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup Label="Globals">
    <SccProjectName>SAK</SccProjectName>
    <SccProvider>SAK</SccProvider>
    <SccAuxPath>SAK</SccAuxPath>
    <SccLocalPath>SAK</SccLocalPath>
  </PropertyGroup>

  <PropertyGroup>
    <TargetFrameworks>net461;netstandard2.0</TargetFrameworks>
    <RootNamespace>SomeRoot.Util</RootNamespace>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="FluentAssertions" Version="5.10.2" />
    <PackageReference Include="xunit" Version="2.4.1" />
  </ItemGroup>
</Project>

我假设由于它引用了xUnit,所以visual和dotnet test命令都把它当作一个测试项目。但是,由于它不是,我想在某种程度上防止visual和dotnet test不承认这个项目是一个测试项目。

删除对xUnit的引用不是一个选项,因为基类需要来自xUnit包的一些接口。

EN

回答 1

Stack Overflow用户

发布于 2022-06-27 17:02:14

基于https://github.com/microsoft/vstest/issues/1129,它似乎检查了两件事情:IsTestProject属性和TestContainerProjectCapability项。为了安全起见,我把两者都移走了。

将其添加到项目文件中:

代码语言:javascript
运行
复制
  <PropertyGroup>
    <IsTestProject>false</IsTestProject>
  </PropertyGroup>

  <ItemGroup>
    <ProjectCapability Remove="TestContainer" />
  </ItemGroup>

这是我在运行时遇到的错误,通过添加以下内容修复了该错误:

代码语言:javascript
运行
复制
========== Starting test discovery ==========
Test project {ProjectName} does not reference any .NET NuGet adapter. Test discovery or execution might not work for this project.
It's recommended to reference NuGet test adapters in each test project in the solution.
Loaded 0 test records from the solution cache in 0.220 sec.
Microsoft.VisualStudio.TestPlatform.ObjectModel.TestPlatformException: Testhost process exited with error: Unhandled exception. System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.TestPlatform.CoreUtilities, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
File name: 'Microsoft.TestPlatform.CoreUtilities, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
   at Microsoft.VisualStudio.TestPlatform.TestHost.Program.Main(String[] args)
. Please check the diagnostic logs for more information.
   at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.ProxyOperationManager.ThrowOnTestHostExited(Boolean testHostExited)
   at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.ProxyOperationManager.SetupChannel(IEnumerable`1 sources, String runSettings)
   at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.ProxyDiscoveryManager.DiscoverTests(DiscoveryCriteria discoveryCriteria, ITestDiscoveryEventsHandler2 eventHandler)
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61864140

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档