本文介绍了在运行时,mstest.exe不会从测试程序集中的app.config文件中读取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们这里有一个有趣的情况.我们拥有VS2013 Premium,可用于使用单元测试框架运行集成测试.由于我们一直在测试不同的安装分支,因此我们在dll的app.config中有一个设置来允许我们 指向我们要测试的分支构建的位置.我们已经这样做了多年.当我们通常从IDE运行测试时,我们将更改项目的设置文件以指向正确的位置,一切都会很愉快.

我们最近尝试使用mstest.exe命令行通过dll执行测试.目标是在运行时之前但在编译后编辑app.config,以更改测试中的安装路径.我们的最终目标是进行测试 无需重新编译即可在多个VM的各个分支上运行,因此app.config很有意义. app.config中属性的范围是应用程序",而不是用户"

我们的命令行如下  (为清楚起见添加了回车)

"C:\ Program Files(x86)\ Microsoft Visual Studio 12.0 \ Common7 \ IDE \ mstest.exe"

/testcontainer:D:\qatest\CSharpTests\binaries\OurCompany.OurProduct.Test.ModelMenuExe.dll

/testsettings:local.testsettings/test:UpdateWithPointsFromDatabaseAllSamplesOneTriangulation/noisolation

我们将二进制文件(包括.config文件(名称与dll匹配)复制到二进制文件文件夹中".

<设置名称=" SpecificVersionToTestFor" serializeAs =字符串">
                             < value> c:\ program files \ ourcompany \ ourproduct 10.1 dev</value>
           </setting>

我想在编译后更改该值,保存,然后执行上面的mstest命令.执行此操作时,不会读入app.config中的新值.我在消息框中输入了一个用于调试目的的消息,以显示其读取的路径以及该路径 "read"是设置文件在编译时的内容.我使用DotPeek提取了我们的测试程序集,并且dll中的settings/app.config 中有原始值的副本

       [global :: System.Configuration.ApplicationScopedSettingAttribute()]
       [global :: System.Diagnostics.DebuggerNonUserCodeAttribute()]
       [global :: System.Configuration.DefaultSettingValueAttribute("c:\\ program files \\ ourcompany \\ ourproduct 10.1 dev")]
      公共字符串SpecificVersionToTestFor {  get {return((string)(this ["SpecificVersionToTestFor"]]);

 我尝试过使用/不使用/noisolation标志.

关于正在发生的事情的任何想法

解决方案


Hi

We have an interesting situation here.  We have VS2013 Premium which we use to run our integration tests using the unit test framework.  As we are always testing different install branches, we have a setting in our dll's app.config to allow us to point to the location of the branch build we want to test. We have been doing this for years. As we typically run the tests from the IDE, we would change the project's settings file to point to the correct location and everything is happy.

We have recently tried using the mstest.exe command line to execute the tests via a dll.  The goal is the edit the app.config prior to runtime, but after compile, to change the install path under test.  Our final goal would be to run the tests on various branches on several VMs without needing to recompile, so therefore the app.config makes sense.  The scope of properties in the app.config is "application", not "user"

Our command line is as follows  (carriage returns added for clarity)

"C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\mstest.exe"

/testcontainer:D:\qatest\CSharpTests\binaries\OurCompany.OurProduct.Test.ModelMenuExe.dll

/testsettings:local.testsettings /test:UpdateWithPointsFromDatabaseAllSamplesOneTriangulation /noisolation

We copy the binaries, including the .config files (names match dlls) to a binaries folder. Our app.config has this line

<setting name="SpecificVersionToTestFor" serializeAs="String">
                <value>c:\program files\ourcompany\ourproduct 10.1 dev</value>
            </setting>

I want to change the value after compile, save, then execute the mstest command above.  When I do this, the new value in app.config is not read in.  I put in a messagebox for debug purposes to display the path that it read,  and the path it read is the one in the settings file at compile time.  I used DotPeek to extract our test assembly and there is a copy of the original values from the settings/app.config in the dll

        [global::System.Configuration.ApplicationScopedSettingAttribute()]
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
        [global::System.Configuration.DefaultSettingValueAttribute("c:\\program files\\ourcompany\\ourproduct 10.1 dev")]
        public string SpecificVersionToTestFor { get {return ((string)(this["SpecificVersionToTestFor"]));

 I have tried with and without the /noisolation flag.

Any ideas as to what is happening

解决方案


这篇关于在运行时,mstest.exe不会从测试程序集中的app.config文件中读取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-06 01:52