Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't read app.config settings within test methods #17

Closed
infl3x opened this issue May 3, 2015 · 16 comments
Closed

Can't read app.config settings within test methods #17

infl3x opened this issue May 3, 2015 · 16 comments

Comments

@infl3x
Copy link

infl3x commented May 3, 2015

Hello,
I'm attempting to use the latest CTP release of the VS adapter and am running into issues reading app settings from my app.config file in the test project.

I've created a simple test project with the following test:

        [Test]
        public void ShouldReadAppConfigSetting()
        {
            Assert.That(ConfigurationManager.AppSettings["TestConfigSetting"], Is.Not.Null);
        }

...And added the following to the app.config file for the test project:

  <appSettings>
      <add key="TestConfigSetting" value="omg" />
  </appSettings>

I have been able to get around this issue using the console runner by specifying -domain:multiple.

If I switch Visual Studio back to the the old v2.x test adapter, the test passes.

@CharliePoole
Copy link
Contributor

This is confirmed. The test adapter does not set the config file location for the test domain.

@CharliePoole CharliePoole added this to the 3.0-ctp-2 milestone May 4, 2015
@CharliePoole CharliePoole self-assigned this May 4, 2015
@marklam
Copy link

marklam commented May 6, 2015

Would a fix for this also make bindingRedirect work?

@CharliePoole
Copy link
Contributor

Yes, so long as it's in the config file named for the assembly being loaded.

@marklam
Copy link

marklam commented May 6, 2015

It's in the .exe.config for an exe using NUnitLite 3, so I think so.
Thanks.

CharliePoole added a commit that referenced this issue May 16, 2015
Add tests to verify that #17 is fixed; cateorize tests by expected result
@ravensorb
Copy link

This issue seems to still exist. Did something change recently that would cause it to no longer work?

@OsirisTerje
Copy link
Member

@ravensorb There are 2 tests in the NUnit Demo project for this, and they both are working.
Please check https://github.com/nunit/nunit3-vs-adapter-demo and the tests in class ConfigFileTests

If you still have a fail, please raise a new issue with a small repro project

@ravensorb
Copy link

Hmm, I looked at that and I don't see any test that is reading from ConfigurationManager.AppSettings -- am I missing something?

Note -- these tests also fail in VS2019

@OsirisTerje
Copy link
Member

OsirisTerje commented Feb 3, 2019

Did you look at https://github.com/nunit/nunit3-vs-adapter-demo/blob/master/src/csharp/ConfigFileTests.cs ?

[Test] public static void CanReadConfigFile() { Assert.That(ConfigurationManager.AppSettings.Get("test.setting"), Is.EqualTo("54321")); }

If it still doesn't work for you, can you please create a small repro and upload it ? It should work "as is".

@ravensorb
Copy link

Ok, I was looking in the .netcore test project.

Few things observed

  • CSharpTestDemo
    • project will not execute in VS2019 (test discovery doesn't seem to work). Adding reference to test adapter for visual studio allows it to run inside VS
    • 20 test cases fail in VS2019 (some might be expected to fail though so its hard to tell if this is a correct result)
  • NUnit3CoreTestDemo
    • AppDomain.CurrentDomain.SetupInformation doesn't exist in anything newer than core 1.0 (fails in core 1.1 and 2.0 as well as netstandard 2.0). I think the code needs to move to using ConfigurationBuilder correct?

From my side, I am switching over my code to using ConfigurationBuilder as well so I think I am good now.

Thanks!

@CharliePoole
Copy link
Contributor

Purpose of the test demo is for us to see how the tests appear in the IDE so done of them fail. If you display by traits, you'll see expected failures, etc.

@OsirisTerje
Copy link
Member

@ravensorb I just checked with VS 2019, and it works. Discovery is working, and so is running them.

image

I see a couple of tests there (marked red) that has unexpected results, but I havent checked them in VS2017 yet. But all in all, this works.

@ravensorb
Copy link

Yep that aligns for the most part with what I was seeing after I added the test runner. So that makes complete sense. For the netcore one, I could probably do a PR for the new configuationbuilder if that would be useful.

@OsirisTerje
Copy link
Member

Absolutely! Please do!

@OsirisTerje
Copy link
Member

I also noted now, that I have been a bit sloppy here, I have upgraded and added the TestAdadpter in a separate branch, and forgot to push it up and raise a PR for it. Shame on me :-|
That also makes sense out of your comments above, so my apologies for that.
I'll push up now and raise PR, and if you @ravensorb can add the fixes for the netcore, it would be awesome!

@jilani-blend
Copy link

My App.Config file is not readable in Test Project. it works fine in the simple class library.

@OsirisTerje
Copy link
Member

OsirisTerje commented Aug 13, 2021

Repro please

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants