NUnit에서 .config 파일 사용하기

  • Post author:
  • Post category:
  • Post comments:0 Comments
  • Post last modified:January 14, 2005

이전에도 이와 관련된 글을 올렸었습니다.

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

 

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Inline Feedbacks
View all comments