오늘 마이크로소프트 Patterns & Practice 이 배포한 ExceptionManagement라는 ApplicationBlock을 이용한 모듈을 테스트하던 중 다음과 같은 문제를 발견했습니다.
아래 자료는 http://www.testdriven.com 와 http://discuss.develop.com 에서 가져왔습니다.
[질문 1]
The configuration settings always reads from the .config of the EXE the
.dll is running in. In this case, NUnitGUI.exe or Nant.exe
Anyone know of a way to explicitly set the config file to read from?
[질문 2]
How can I get access to a web application’s
ConfigurationSettings.GetConfig() from within an NUnit test? It
appears that NUnit is accessing its own configuration settings.
Running this test:
[Test] public void TestGetConfig()
{
try
{
NameValueCollection configSettings = NameValueCollection)ConfigurationSettings.GetConfig(“appSettings”);
Assert.IsNotNull(configSettings);
}
catch(System.Exception ex)
{
Console.WriteLine(“Exception” + ex.ToString());
}
}
configSettings gets an “undefined value,” I get a
ExceptionNUnit.Framework.AssertionException exception:
How can I retrieve my appSettings from a simple NUnit test?
John Tobler
[email protected]
[답변 1]
I seem to remember reading somewhere that the config file has to be in the
same directory as the dll that Nunit is loading, and that it has to be named
.dll.config.
[답변 2]
Bob,
You are right. I am in the process of restructuring an open source project
called Draco.NET, and need to test configuration section loading for a core
assembly that is loaded into a service. Since configs are for app domains,
they dont directly map to library assemblies. Adding an app.config to the
library assembly project does not achieve the same effect when adding the
config to an executable assembly – the app.config is not copied into the bin
directory. But as you advise Bob, if you create an app config file with the
name of your dll
, copy it into the bin directory
manually, you will be able to access it as normal. Having the test rig copy
the config file into the bin directory is trivial.
nick.robinson
site : http://www.fromconcept.co.uk
blog : http://www.fromconcept.co.uk/weblog.aspx