Develop and run MSTest unit tests in Visual Studio 2010 without including .vsmdi and .testsettings

前端 未结 1 1086
醉酒成梦
醉酒成梦 2021-02-04 14:59

I know this is somehow possible, as we have a project that contains MSTest unit tests that are runnable via the VS2010 test runner. We can even add new test met

相关标签:
1条回答
  • 2021-02-04 15:47

    You can indeed run tests within VS without having the .vsmdi and .testsettings files (infact, you can just delete them after adding the test project)

    So why doesnt it work with a normal class library? the awnser lies inside the .csproj file. This is a regular class library:

    <PropertyGroup>
      <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
      <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
      <ProductVersion>8.0.30703</ProductVersion>
      <SchemaVersion>2.0</SchemaVersion>
      <ProjectGuid>{F191EC72-AFDF-49CE-A918-01905E7C32EF}</ProjectGuid>
      <OutputType>Library</OutputType>
      <AppDesignerFolder>Properties</AppDesignerFolder>
      <RootNamespace>test</RootNamespace>
      <AssemblyName>test</AssemblyName>
      <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
      <FileAlignment>512</FileAlignment>
    </PropertyGroup>
    

    And this is a test project:

    <PropertyGroup>
      <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
      <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
      <ProductVersion>8.0.30703</ProductVersion>
      <SchemaVersion>2.0</SchemaVersion>
      <ProjectGuid>{F191EC72-AFDF-49CE-A918-01905E7C32EF}</ProjectGuid>
      <OutputType>Library</OutputType>
      <AppDesignerFolder>Properties</AppDesignerFolder>
      <RootNamespace>test</RootNamespace>
      <AssemblyName>test</AssemblyName>
      <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
      <FileAlignment>512</FileAlignment>
      <ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
    </PropertyGroup>
    

    That last element, ProjectTypeGuids is what tells VS that its a project that you can run MSTest tests on. these guids are always the same as far as i know, [at least given the same version of VS] so you should be able to paste that line into any .csproj file and have VS recognize the tests inside.

    The test settings file can be useful to specify options for deployment (and alot of other things) but most of the options can also be specified at the command line to mstest.exe

    The .vsmdi can also be replaced by adding attributes to your test methods. most if not all options available in the Properties for a test can be set as attributes as well as in the vsmdi file. i generally prefer the attributes as they are 'closer' to the code.

    0 讨论(0)
提交回复
热议问题