English 中文(简体)
AppConfig in a VS 2008 test project?
原标题:

I ve just added my first test project to a VS 2008 solution. I have a component I d like to use in a unit test; the component calls System.Configuration.ConfigurationSettings.GetConfig() to get a setting, and I d like for that call to work in my test. Any ideas how I can do this? I don t see any app.config in the project, so I m not sure if that s an option in this instance. Thanks!

最佳回答

Thanks guys. Great info, but what I wound up putting an App.Config in the test project and adding the appropriate sections in it. Works good now.

问题回答

Take a look here : Unit testing the app.config file with NUnit

I believe you can set up a config file to work with the test runner. Find its executable and use a post-build action to copy the application file to "[TestRunner.exe].config".

You can mock that call. Using TypeMock, you would go like this:

var mockConfigurationManager = MockManager.Mock(typeof(ConfigurationManager));
var appSettings = new NameValueCollection { { "key", "value" } };
mockConfigurationManager.ExpectGetAlways("AppSettings", appSettings);




相关问题
run unit tests and coverage in certain python structure

I have some funny noob problem. I try to run unit tests from commandline: H:PROpyEstimator>python src estpython est_power_estimator.py Traceback (most recent call last): File "src est...

How to unit-test an enterprise symfony project?

I´m working on a huge project at my work. We have about 200 database tables, accordingly a huge number of Models, Actions and so on. How should I begin to write tests for this? My biggest problem ...

Code Coverage Tools & Visual Studio 2008 Pro

Just wondering what people are using for code coverage tools when using MS Visual Studio 2008 Pro. We are using the built-in MS test project and unit testing tool (the one that come pre-installed ...

Unit testing. File structure

I have a C++ legacy codebase with 10-15 applications, all sharing several components. While setting up unittests for both shared components and for applications themselves, I was wondering if there ...

Unit Testing .NET 3.5 projects using MStest in VS2010

There s a bug/feature in Visual Studio 2010 where you can t create a unit test project with the 2.0 CLR. https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=483891&wa=...

Unit Test for Exceptions Message

Is there a simple (Attribute-driven) way to have the following test fail on the message of the exception. [TestMethod()] [ExpectedException(typeof(ArgumentException))] public void ExceptionTestTest() ...

热门标签