NUnit의 ConfigurationSettings( .config 파일 ) 지원 문제

  • Post author:
  • Post category:
  • Post last modified:December 4, 2010

오늘 마이크로소프트 Patterns & Practice 이 배포한 ExceptionManagement라는 ApplicationBlock을 이용한 모듈을 테스트하던 중 다음과 같은 문제를 발견했습니다.
아래 자료는 http://www.testdriven.comhttp://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

 

Author Details
Kubernetes, DevSecOps, AWS, 클라우드 보안, 클라우드 비용관리, SaaS 의 활용과 내재화 등 소프트웨어 개발 전반에 도움이 필요하다면 도움을 요청하세요. 지인이라면 가볍게 도와드리겠습니다. 전문적인 도움이 필요하다면 저의 현업에 방해가 되지 않는 선에서 협의가능합니다.