Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 896377
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T14:43:12+00:00 2026-05-15T14:43:12+00:00

we use the nunit.exe application to run our (integration)test Now i experience the problem

  • 0

we use the nunit.exe application to run our (integration)test

Now i experience the problem that the connectionstring is not picked up from the app.config from the dll where the testcode is in.

That sounds logical because the nunit.exe is the starting app and not the test dll (it used to work when i started the tests from the visual studio testframework by the way), but should i put the connectionstrings in the nunit.exe.config?

I tried setting them in the testcode (works for the appsettings : ConfigurationManager.AppSettings.Set("DownloadDirectory", mDir);) like this:
ConfigurationManager.ConnectionStrings.Add(conset); (where conset is a ConnectionStringSettings object), but then i get the error that the connectionstrings section is readonly.

What should i do to use the connectionstrings in my test?

EDIT:
we use the entity framework so we can’t put the connectionstring in the appsettings because it reads from the section directly, i couldn’t find a way to work around this behaviour.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T14:43:14+00:00Added an answer on May 15, 2026 at 2:43 pm

    Using reflection, you can (in memory) change your value of the Configuration.ConnectionStrings[connectionName], which in your case you would probably do in SetUp or perhaps TestFixtureSetUp. See http://david.gardiner.net.au/2008/09/programmatically-setting.html.

    // Back up the existing connection string
    ConnectionStringSettings connStringSettings = ConfigurationManager.ConnectionStrings[connectionName];
    string oldConnectionString = connStringSettings.ConnectionString;
    
    // Override the IsReadOnly method on the ConnectionStringsSection.
    // This is something of a hack, but will work as long as Microsoft doesn't change the
    // internals of the ConfigurationElement class.
    FieldInfo fi = typeof(ConfigurationElement).GetField("_bReadOnly", BindingFlags.Instance | BindingFlags.NonPublic);
    fi.SetValue(connStringSettings, false);
    
    // Set the new connection string value
    connStringSettings.ConnectionString = connectionStringNeededForNUnitTest;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use NUnit integration tests. I am trying to test to make sure that
I am wondering how to use NUnit correctly. First, I created a separate test
I'm trying to use the MSBuild NUnit community task to force tests to run
Does MSTest have standalone GUI similar to nUnit that lets me use it and
I'm starting to use NUnit to write test cases in C# with Visual Studio
I usually use NUnit as a UnitTest Framework ,however where I work now they
I am learning how to use NUnit. I have my main project in it's
I am interested in seeing if I can improve the way we use NUnit
The NUnit documentation doesn't tell me when to use a method with a TestFixtureSetup
Use case: 3rd party application wants to programatically monitor a text file being generated

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.