单元测试过程中获取引用的项目路径 [英] Get path of referenced project during unit testing

查看:193
本文介绍了单元测试过程中获取引用的项目路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试着在我的(ASP.Net)web应用测试类的功能,使用单元测试。这个类从硬盘(执行XSL转换)加载一些文件:

I try test the functionality of a class in my (ASP.Net) webapplication, using unit tests. This class loads some files from harddrive (to perform xsl transformations):

Xsl = GetXSLFromFile(AppDomain.CurrentDomain.BaseDirectory + "\XML Transformationen\Transformation_01.xslt")

此路径的web应用本身的调试过程中正确地解析。但每当我开始单元测试(驻留在一个单独的测试项目,它引用了web应用的项目),我得到的测试项目,而不是路径。

This path is correctly resolved during debugging of the webapplication itself. But whenever I start the unit test (which resides in a separate testing project, referencing the project of the webapplication), I get the path of the testing project instead.

时有可能得到的web应用的路径在这种情况下,还是我必须使用不同的方法?
任何提示赞赏。

Is it possible to get the path of the webapplication in this scenario, or do I have to use a different approach? Any hints are appreciated.

亲切的问候,
凯哈特曼

Kind regards, Kai Hartmann

推荐答案

好吧,这给了暗示:的一个单元测试项目可以加载目标应用程序的app.config文件?

Ok, this gave the hint: Can a unit test project load the target application's app.config file?

在.testsettings文件,由测试添加项目到我的web应用的项目,我可以添加文件和文件夹,应在每次执行测试的时间复制到测试项目debug文件夹。

In the .testsettings file, added by the testing project to my webapplication project, I can add files and folders which should be copied to the testing projects debug folder each time the test is executed.

所以,在这之后我可以引用每AppDomain.CurrentDomain.BaseDirectory的XSL-文件。

So after this I can reference the xsl-files per AppDomain.CurrentDomain.BaseDirectory.

此外,为了还留着文件夹结构,我不得不做的已经在这里描述:
Visual Studio的测试项目 - 不能在部署文件夹复制

Additionally, to keep also the folder structure, I had to do what has been described here: Visual Studio Test Project - Does not copy folder on deployment

我不得不编辑.testsettings使用文本编辑器文件,并添加输出目录参数。从那以后,我重新启动Visual Studio中,并开始测试项目的文件夹和文件已被正确复制时。

I had to edit the .testsettings file with a text editor, and add the outputDirectory parameter. After that I restarted Visual Studio, and when started the testing project the folder and files have been copied correctly.

这篇关于单元测试过程中获取引用的项目路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆