0

I have created a unit test in a separate project. I am trying to change a filepath I have as a setting in the main project. I access the path as My.Settings.FooBarPath. I can't figure out how to change it in my unit test. How do I access the settings in my main project from the unit test project and how do I change the values?

I have read this post: Modifying application settings in unit tests

The second answer seemed to be the most useful but I couldn't quite seem to get it to work for my unit tests.

Community
  • 1
  • 1

2 Answers2

0

One way is to modify the settings.xml file manually. It's a bit convoluted, but this tutorial might help for saving and loading text files into your app (of course you'd do it without a UI) - https://www.youtube.com/watch?v=O3nSXaD2J9Q

Another option is to start up your other program with Shell() and have a command line argument for the setting to change and what to change it to.

nasci
  • 46
  • 8
0

The question asked was for VB.Net while the answer given in Modifying application settings in unit tests is for C#. As I had the same question for VB.Net I thought I'd give a VB.Net version of the answer here. Based on the C# answer I got this to work in my project (using Visual Studio 2013) with the following:

  1. The test project should be correctly set up as a unit test for the application under test ("Create and run unit tests" should help in setting it up correctly)

  2. using the fully qualified namespace of the application under test myprojects_namespace.My.settings will give you full (intellisense powered) access to the user settings of the application under test.

After that you can read / write to the user settings as you would normally do. e.g.

myprojects_namespace.My.settings.someProperty = "somevalue"
Assert.AreEqual("somevalue", myprojects_namespace.My.settings.someProperty)

P.S.: I didn't need to add anything in my AssemblyInfo.vb file. There is no reference to System.Runtime.CompilerServices.InternalsVisibleTo as this seems to already have been handled by setting up the unit test project correctly for the application under test.

Community
  • 1
  • 1
  • OK, somehow this doesn't work after all... I'm trying to get the current values (in my case these are user settings) I get the values set at design time but not the user settings current values ... it's back to the drawing board I'm afraid ... – Marko Pareigis Jun 23 '15 at 16:31