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

  • SEARCH
  • Home
  • 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 4042598
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T13:01:32+00:00 2026-05-20T13:01:32+00:00

I have written some unit tests which depends on a configuration file. This file.config

  • 0

I have written some unit tests which depends on a configuration file. This file.config gets deployed into the bin\Debug directory of my test project. However, it doesn’t seem to get copied into my output test results directory where the test actually takes place.

I have searched and found these:
TFS UnitTesting not deploying local copy assembly to test dir when on build server
Test project and config file

The first link allowed me to find out how to deploy my configuration file into my test project’s bin\Debug directory.

The second presents a working solution, though I find it a little overkill for my needs, not to mention that I add myself a class to test, etc. So, I would prefer a simpler approach which could simply allow me to have this config file copied automatically into my test results directory.

EDIT #1

I’m using:

  1. Microsoft Enterprise Library 4.1 along with its named connections; with
  2. Microsoft Visual Studio 2008; and the
  3. Microsoft UnitTest Framework.

My config file looks like this:

<configuration>
  <configSections>
    <section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
  </configSections>
  <dataConfiguration defaultDatabase="Tests" />
  <connectionStrings>
    <add name="Tests" connectionString="Database=Tests;Server=(local)\SQLEXPRESS;Integrated Security=SSPI"
        providerName="System.Data.SqlClient" />
  </connectionStrings>
</configuration>

and is named: Tests.config.

Now, I have my project settings that contain a DefaultSource parameter which contains the default source name, that is, the for which to create connections and databases objects for. This setting’s value is Tests.

So, when I create a new connection, I simply do it like so:

public static IDbConnection CreateConnection(string source) {
    return new DatabaseProviderFactory(new FileConfigurationSource(
            string.Format("{0}\{1}.config", AppDomain.CurrentDomain.BaseDirectory, source)
        ).CreateDefault().CreateConnection();
}

Now, it is this which doesn’t work properly while unit testing, because of the AppDomain.CurrentDomain.Basedirectory value that is returned. Since this property will not return the assembly build directory bin\Debug, but rather the TestResults[auto-generated-test-results-directory] where the tests actually run.

So, when in my test I do:

[TestMethod()]
public void Connection_InitializationWithSourceName() {
    using connection as IConnection = ConnectionProviderFactory.CreateConnection(DefaultSource) {
        // Asserts here... 
    } 
}

where DefaultSource property will return my default source setting parameter which value is Tests. So, the FileConfigurationSource object class will search for a file called Tests.config in the test results directory where the tests actually run, as stated earlier.

Any idea of how to do it?

Thanks! =)

  • 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-20T13:01:33+00:00Added an answer on May 20, 2026 at 1:01 pm

    Why don’t you just add a postbuild event to you project which copies the file anywhere you like?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm just getting into unit testing, and have written some short tests to check
I have some written a number of unit tests that test a wrapper around
We've all been there. You have written some code and unit tests, the tests
I have written some CSS which targets elements using the parent > child selector.
I have written a custom ErrorProvider which adds some functionality to the existing ErrorProvider
I have a whole bunch of unit tests written in MbUnit and I would
I have written some code that pulls info from a plist file and does
In our big application written with C# we have automated tests. Some of tests
This certainly presupposes that unit testing is a good thing. Our projects have some
I am getting this error when running some unit tests (using the Test::Unit module

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.