Do MSTest deployment items only work when present in the project test settings file?

前端 未结 7 1724
不思量自难忘°
不思量自难忘° 2020-11-28 18:44

I can\'t seem to grasp how MSTest deployment items are supposed to be configured. I have been able to get them working properly by modifying the project\'s test settings fil

相关标签:
7条回答
  • 2020-11-28 19:15

    I thought I'd share a way I ran into problems with MSTest and deployment items. If you Debug/Run your test a 2nd time or more from the "Test Results" window, it uses the settings from a previous run. However, if you Debug/Run the same test from the "Test View" window, it uses the latest settings. I lost an hour to trying to figure out why changes to Local.testsettings weren't being used when I kept starting Debug on the same test from the "Test Results" window.

    This is the Test Results window (do not [re]start tests from here after making changes to Local.testsettings):

    The Test Results Window

    And this is the Test View window (DO start tests from here after making changes to Local.testsettings):

    The Test View Window

    I hope this saves someone a headache in the future.

    0 讨论(0)
  • 2020-11-28 19:17

    If you need separate deployment item in individual test cases then please go ahead and use [DeploymentItem("string file path")] attribute in each test cases.

    0 讨论(0)
  • 2020-11-28 19:18

    In Visual Studio 2012 the output directory is the working directory which means that the DeploymentItem attribute isn't needed for the general case (where you don't have specific per-test or per-class deployment items). This means that if you don't need to use the DeploymentItem attribute if there is a set of files that you want all your tests to use or you are not too pernickety about each TestClass/TestMethod having separate deployment dependencies.

    You can simply click Project | Show All Files and include the subfolders and files in Visual Studio with the 'Copy always' or 'Copy if newer' attribute to your project and the files will be copied to your output directory with hierarchy intact.

    The same applies when running vstest.console.exe from the command line. See here for the details.

    Update

    There are cases where the default directory will not be the output directory. Specifically when you choose Run All Tests the default path would be under TestResults\Deploy_... The same applies when using a runsettings file or tests use DeploymentItems

    The output directory will be the default directory when you are not using DeploymentItems and: -

    • You right click the test(s) in Visual Studio and choose to run / debug, or
    • You run from the command line using vstest.console.exe.
    0 讨论(0)
  • 2020-11-28 19:22

    Looks like this works by default in VS.NET 2012

    0 讨论(0)
  • 2020-11-28 19:23

    In VS 2012, All you need is to make the log4net.properties (or whatever config file for log4net ) file Copy if newer. ( right click log4net.properties file to bring up the properties and configure it )

    0 讨论(0)
  • 2020-11-28 19:26

    For my case, I add the DeploymentItem attribute, it can't take effect immediately. I have to close and re-open the solution, then the configured DeploymentItem attributes will take effect.

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