Specify MSTest parameters in MSBuild

北战南征 提交于 2020-01-25 04:46:25

问题


I'm trying to prevent certain (MSTest) unit tests from being run on our build server. I'd really like to just add a TestCategory, and then specify:

/category:"!RequiresLoginCredentials"

But I'm not sure how to indicate that in the msbuild project file.

The relevant section of the build file currently has:

  <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>

I'm guessing this is a simple addition, but I know very little about msbuild.

Thanks!


回答1:


I did a quick search for the answer and I think there are two possible solutions:

  1. From what you described, looks like you're trying to run the tests using the TestToolTask task of MSBuild. Unfortunately, I don't think you can pass MSTest arguments directly to this task. To accomplish what you want, you need to specify the tests you want to run in a test list, and pass the test list to this task. You need to use the MetadataFile property as shown in the example in your post.

  2. You can invoke MSTest.exe directly using the Exec task of MSBuild. This way you have the freedom to pass in the arguments you want.



来源:https://stackoverflow.com/questions/6061282/specify-mstest-parameters-in-msbuild

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!