How can you use “external” configuration files (i.e. with configSource) with an MSTest unit test project?

后端 未结 3 855
误落风尘
误落风尘 2021-02-05 22:53

For simplicity, I generally split a lot of my configuration (i.e. the contents of app.config and web.config) out into separate .config files, and then reference them from the ma

3条回答
  •  無奈伤痛
    2021-02-05 23:16

    Test run configurations are a bit awkward when trying to run tests outside of Visual Studio.

    For command line execution using MSTest they become quite cumbersome to keep "clean". They are also "global" to the solution so external files will be copied for every test project.

    I much prefer the DeploymentItem attribute.

    [TestMethod]
    [DeploymentItem(@"test_data.file")]
    public void FooTest()
    {...}
    

    Makes the tests independent of the .testrunconfig files.

提交回复
热议问题