如何在Visual Studio 2015中的“创建单元测试”上下文菜单中添加其他测试项目?

时间:2016-07-19 09:47:57

标签: visual-studio unit-testing visual-studio-2015 xunit

如何在Visual Studio 2015中的“创建单元测试”的右键单击上下文菜单中添加现有的测试项目?

它只显示一个测试项目(项目是使用右键单击上下文操作创建的)。另一个项目是使用新项目向导创建的,未显示。

Missing Projects Available Unit Test Projects

有没有办法将现有的单元测试项目添加到下拉列表中?

1 个答案:

答案 0 :(得分:1)

我没有确定哪些步骤是强制性的,但下面是允许我将现有项目添加到Intellitest"创建单元测试"列表:

  • 参考Microsoft.Pex.Framework汇编
  • 添加" PexAssemblyInfo.cs"文件在属性项目的特殊文件夹中。相应地编辑。
  • 在.csproj文件中,在<TestProjectType>"UnitTest"</TestProjectType> node
  • 中添加<PropertyGroup>标记
  • 在.csproj文件中,在<IsCodedUITest>False</IsCodedUITest> node 中添加<PropertyGroup>标记(可能不需要)
  • 在.csproj文件中,添加&#34; {3AC096D0-A1C2-E12C-1390-A8335801FDAB}&#34; (测试项目类型)到<ProjectTypeGuids>标记

编辑示例PexAssemblyInfo.cs内容

using Microsoft.Pex.Framework.Coverage;
using Microsoft.Pex.Framework.Creatable;
using Microsoft.Pex.Framework.Instrumentation;
using Microsoft.Pex.Framework.Settings;
using Microsoft.Pex.Framework.Validation;

// Microsoft.Pex.Framework.Settings
[assembly: PexAssemblySettings(TestFramework = "xunit-2.0")]

// Microsoft.Pex.Framework.Instrumentation
[assembly: PexAssemblyUnderTest("{YOUR-PROJECT-NAME}")]
[assembly: PexInstrumentAssembly("System.Runtime.Extensions")]
[assembly: PexInstrumentAssembly("System.Linq.Expressions")]
[assembly: PexInstrumentAssembly("System.Threading")]
[assembly: PexInstrumentAssembly("System.Reflection.Extensions")]
[assembly: PexInstrumentAssembly("System.Reflection")]
[assembly: PexInstrumentAssembly("System.Diagnostics.Debug")]
[assembly: PexInstrumentAssembly("System.Runtime")]
[assembly: PexInstrumentAssembly("System.Threading.Tasks")]
[assembly: PexInstrumentAssembly("System.Collections")]

// Microsoft.Pex.Framework.Creatable
[assembly: PexCreatableFactoryForDelegates]

// Microsoft.Pex.Framework.Validation
[assembly: PexAllowedContractRequiresFailureAtTypeUnderTestSurface]
[assembly: PexAllowedXmlDocumentedException]

// Microsoft.Pex.Framework.Coverage
[assembly: PexCoverageFilterAssembly(PexCoverageDomain.UserOrTestCode, "System.Runtime.Extensions")]
[assembly: PexCoverageFilterAssembly(PexCoverageDomain.UserOrTestCode, "System.Linq.Expressions")]
[assembly: PexCoverageFilterAssembly(PexCoverageDomain.UserOrTestCode, "System.Threading")]
[assembly: PexCoverageFilterAssembly(PexCoverageDomain.UserOrTestCode, "System.Reflection.Extensions")]
[assembly: PexCoverageFilterAssembly(PexCoverageDomain.UserOrTestCode, "System.Reflection")]
[assembly: PexCoverageFilterAssembly(PexCoverageDomain.UserOrTestCode, "System.Diagnostics.Debug")]
[assembly: PexCoverageFilterAssembly(PexCoverageDomain.UserOrTestCode, "System.Runtime")]
[assembly: PexCoverageFilterAssembly(PexCoverageDomain.UserOrTestCode, "System.Threading.Tasks")]
[assembly: PexCoverageFilterAssembly(PexCoverageDomain.UserOrTestCode, "System.Collections")]