0

我正在编写一个测试用例,其中被测方法验证路径是否存在。该路径位于输出程序集的文件夹中。所以我有代码来获取文件夹路径作为字符串 assemblyLocation = typeof(ReportViewer).Assembly.Loaction;

ReportViewer 存在于同一个程序集中。当我运行测试用例时,它最终选择了正在运行的程序集测试用例的文件夹的路径。

当我运行应用程序时,被测方法返回正确的路径,但在测试用例期间,它为我提供了测试程序集的路径。任何线索为什么?

我使用 MSTest 作为测试框架。

4

1 回答 1

0

You didn't specify what unit testing framework you are using, however, in Visual Studio Professional (and above) built-in tests, tests are executed from test assembly in test result's out directory and all referenced assemblies are copied there.

FYI, if your code depends on any non referenced assemblies (loaded with reflection or unmanaged assemblies) or any other resources that need to be in execution directory, then you will need to copy them there during the tests' class initialize (which is ran before constructor).

This enables flexible configuration of testing environment (e.g. separate app.config file).

Edit - Reply to comment:

The code returns the correct result - execution directory, I assume the reason you are looking for the bin directory is that you have some resources under there. If this is the case, copy them to the tests' out dir before the test starts (in the tests' class's class initialize method).

于 2011-06-22T19:34:37.737 回答