[英]Error with unit testing and MEF
I am trying to use unit testing in an application that uses MEF to load plugins. 我正在尝试在使用MEF加载插件的应用程序中使用单元测试。
The line of code: 代码行:
var dirCatalog = new DirectoryCatalog(
Path.Combine(
Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
"Plugins"));
Works perfectly fine in debug or release mode. 在调试或发布模式下工作正常。
But if I am running a test or debugging a test it just closes the testing. 但是,如果我正在运行测试或调试测试,它将关闭测试。 No exception caught.
没有异常捕获。 Nothing.
没有。
I've check that the path is correct. 我检查了路径是否正确。
I have a desktop application where the business logic library makes heavy use MEF and includes a number of unit tests. 我有一个桌面应用程序,其中业务逻辑库大量使用MEF并包含许多单元测试。 I built my catalog using
AppDomain.BaseDirectory
: 我使用
AppDomain.BaseDirectory
构建了目录:
var location = AppDomain.CurrentDomain.BaseDirectory;
var dirCatalog = new DirectoryCatalog(Path.Combine(location, "Plugins"));
If it needs to run both in a desktop application and in the web application, try using AppDomain.RelativeSearchPath
: 如果需要同时在桌面应用程序和Web应用程序中运行,请尝试使用
AppDomain.RelativeSearchPath
:
var location = AppDomain.CurrentDomain.RelativeSearchPath ??
AppDomain.CurrentDomain.BaseDirectory;
var dirCatalog = new DirectoryCatalog(Path.Combine(location, "Plugins"));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.