app.configs和MSTest的项目 - 连接字符串空引用 [英] app.configs and MSTest Project - null reference for a connection string

查看:179
本文介绍了app.configs和MSTest的项目 - 连接字符串空引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我试图运行单元测试(MSTest的),我遇到了这个问题。
的code线:

When I try to run Unit Tests (mstest) I run into this issue.
The line of code:

_mainCnStr = System.Configuration.ConfigurationManager.
               ConnectionStrings["main"].ConnectionString;

回来为空引用

Comes back as a null reference

这当我运行它并没有做到这一点,在主界面的项目。什么是正确的方法来获取该连接字符串设定看到的单元测试项目?我试图嵌入的资源。我想一直拷贝。什么是设置的最佳组合,这将解决这个问题对我?

It doesn't do this in the main UI project when I run it. What is the right method to get this connection string setting seen by the Unit Test project? I tried embedded as a resource. I tried Copy Always. What is the right combination of settings that will fix this for me?

推荐答案

您应该添加的app.config 的单元测试项目。它不会自动使用在设置UI应用程序的的app.config

You should add an app.config to the unit test project. It won't automatically use the settings in UI application's app.config.

这篇关于app.configs和MSTest的项目 - 连接字符串空引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆