admin管理员组

文章数量:1401171

I have the following unit test (simplified).

using Microsoft.VisualStudio.TestTools.UnitTesting;


[TestClass]
public class UnitTest1
{
    
    [TestMethod]
    public void T001b_BasePairs()
    {
        var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
        Console.WriteLine($"Configuration file path: {config.FilePath}");
       
        var connectionStrings = ConfigurationManager.ConnectionStrings;
        var connectionStringName = connectionStrings[0].Name;
        Console.WriteLine($"Connection string name: {connectionStringName}");`

In the debugger I see UnitTestProjectCore\bin\Debug\net8.0-windows\testhost.dll

I expected the code to find connectionstrings from my app.config in the connectionStrings section.

本文标签: app configHow do I set up a configuration file to hold connection strings for a unit testStack Overflow