이전에도 이와 관련된 글을 올렸었습니다.
NUnit을 사용하는 환경에서 .Config 파일을 사용하는 응용프로그램이나 라이브러리를 제작한다면 반드시 알아두어야 하는 사항입니다.
아래 글을 오늘 Unit Test에 관한 글을 뒤지다가 찾았습니다. 저도 아래와 같은 방법으로 작업하고 있었는데, 이렇게 정리가 잘된 글이 있으니 제가 직접 글 쓸 필요는 없을 것 같습니다.
Tip for Using App.Config files with NUnit from Visual Studio
At some point you may very well need to call code like the following from your test class library project:
string myValue = ConfigurationSettings.AppSettings[“Data.Key”];
Subsequently, when running NUnit you may find that no value is returned from the expression above. This is because NUnit is looking for an xml configuration file with the same name as the assembly + .config in the directory the loaded assembly is running from.
Example: Suppose your assembly is located at C:\Code\My Project\MyAssembly.dll For the ConfigurationSettings.AppSettings call to work properly, you need to have a file at c:\Code\My Project\MyAssembly.dll.config.
Well, an easy way to automate the creation of this file from Visual Studio is to right-click on the project and choose properties from the context menu. Then, under common properties -> build events, add set the following value for the Post-Build Event Command Line:
copy $(ProjectDir)App.config $(TargetPath).config
This will make Visual Studio copy the App.Config file into the appropriate bin\Debug or bin\Release directory (depending on the current configuration) so NUnit will find the file. Happy Unit Testing!
출처: http://www.xml-blog.com/archives/000231.html