本文介绍了麻烦NUnit的决定时,在大会目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚开始用NUnit的,以提供一些测试覆盖率为我的项目工作。

I've just started to work with NUnit in order to provide some test coverage for my projects.

在我的主要library.dll我需要从去与库外部文件加载的配置数据,library.xml。

Within my main library.dll I need to load up configuration data from an external file that goes with the library, library.xml.

这工作得很好,当我使用该库,因为我使用以下方法来获得,在其中查找配置文件的目录:

This works fine when I'm using the library, because I use the following to get the directory in which to look for the config file:

string settingspath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);

我注意到的问题是,当我的单元测试与NUnit的,它复制了我的程序集的卷影副本,但没有采取任何其他文件吧,所以当然我初始化失败,因为丢失配置文件。

The problem I've noticed is that when I'm unit testing with NUnit, it copies my assemblies to a Shadow Copy, but doesn't take any of the other files with it, so of course my init fails due to missing config files.

我应该做不同的东西从我的库中找到的配置文件? (这是一个服务器应用程序,我不希望使用标准应用程序设置,或用户的本地设置等)

Should I be doing something different to locate config files from within my library? (it's a server app, and I don't want to use the standard app settings, or user's local settings, etc)

推荐答案

在单元测试一般建议,以避免外界的依赖,例如文件系统和数据库,以嘲讽/删空调用它们的程序 - 这样你测试是更本地化,不那么脆弱,速度更快。看看你是否可以通过提供假的配置信息中删除的依赖关系。

When unit testing it is generally recommended to avoid external dependencies such as the file system and databases, by mocking/stubbing out the routines that call them - that way your tests are more localised, less fragile and faster. See if you can remove the dependencies by providing fake configuration information.

这篇关于麻烦NUnit的决定时,在大会目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 23:38