在MSBuild中指定MSTest参数

Ada*_*kis 1 msbuild mstest

我试图阻止某些(MSTest)单元测试在我们的构建服务器上运行.我真的只想添加一个TestCategory,然后指定:

/category:"!RequiresLoginCredentials"
Run Code Online (Sandbox Code Playgroud)

但我不确定如何在msbuild项目文件中指出.

构建文件的相关部分目前具有:

  <ItemGroup>
    <!--  TEST ARGUMENTS
     If the RunTest property is set to true then the following test arguments will be used to run 
     tests. Tests can be run by specifying one or more test lists and/or one or more test containers.

     To run tests using test lists, add MetaDataFile items and associated TestLists here.  Paths can 
     be server paths or local paths, but server paths relative to the location of this file are highly 
     recommended:

        <MetaDataFile Include="$(BuildProjectFolderPath)/HelloWorld/HelloWorld.vsmdi">
            <TestList>BVT1;BVT2</TestList>
        </MetaDataFile>

     To run tests using test containers, add TestContainer items here:

        <TestContainer Include="$(OutDir)\HelloWorldTests.dll" />
        <TestContainer Include="$(SolutionRoot)\TestProject\WebTest1.webtest" />
        <TestContainer Include="$(SolutionRoot)\TestProject\LoadTest1.loadtest" />

     Use %2a instead of * and %3f instead of ? to prevent expansion before test assemblies are built
    -->
    <TestContainer Include="$(OutDir)\UnitTests.dll" />

  </ItemGroup>
Run Code Online (Sandbox Code Playgroud)

我猜这是一个简单的补充,但我对msbuild知之甚少.

谢谢!

Dua*_* Le 5

我快速搜索了答案,我认为有两种可能的解决方案:

  1. 根据您的描述,看起来您正在尝试使用MSBuild 的TestToolTask​​任务来运行测试.不幸的是,我认为你不能直接将MSTest参数传递给这个任务.要完成所需,您需要指定要在测试列表中运行的测试,并将测试列表传递给此任务.您需要使用MetadataFile属性,如帖子中的示例所示.

  2. 您可以使用MSBuild 的Exec任务直接调用MSTest.exe .这样你就可以自由地传递你想要的参数.