简体   繁体   English

如何在Visual Studio中使用XUnit来对在远程进程中运行的代码进行单元测试

[英]How to use XUnit with Visual studio to unit test code running in a remote process

We are writing plugins for the Solidworks CAD system. 我们正在为Solidworks CAD系统编写插件。 Writing an addin involves compiling a DLL, registering it and then starting solidworks. 编写插件涉及编译DLL,注册它然后启动solidworks。 Code in the dll can be configured to execute as soon as solidworks starts. 可以将dll中的代码配置为在solidworks启动后立即执行。

What I would like to do is craft a special DLL so that it runs a series of unit tests or a single unit test from visual studio and reports the results back to visual studio in the standard way. 我想做的是制作一个特殊的DLL,以便它从visual studio运行一系列单元测试或单个单元测试,并以标准方式将结果报告给visual studio。

We are happy to use either the standard visual studio test or resharper test system. 我们很高兴使用标准的视觉工作室测试或resharper测试系统。

Is it possible to write an extension to the unit test system to achieve this. 是否可以为单元测试系统编写扩展来实现此目的。 If so how difficult is this to achieve. 如果是这样的话,实现起来有多困难。 Perhaps there are extensions that already do something similar for other plugin type environments that need testing. 也许有些扩展已经为需要测试的其他插件类型环境做了类似的事情。

We wrote a plugin for XUnit that solves this problem 我们为XUnit编写了一个插件来解决这个问题

https://github.com/Weingartner/XUnitRemote https://github.com/Weingartner/XUnitRemote

and a specific solution using the above is for unit testing solidworks 并且使用上述的特定解决方案用于单元测试solidworks

https://github.com/Weingartner/SolidworksAddinFramework https://github.com/Weingartner/SolidworksAddinFramework

An example test with example custom facts 使用示例自定义事实的示例测试

namespace XUnitRemote.Test
{
    public class Tests
    {
        private readonly ITestOutputHelper _Output;

        public Tests(ITestOutputHelper output)
        {
            _Output = output;
        }

        [SampleProcessFact]
        public void OutOfProcess()
        {
            _Output.WriteLine("Process name: " + Process.GetCurrentProcess().ProcessName);
            Assert.Equal(5, 3);
        }

        [Fact]
        public void InProcess()
        {
            _Output.WriteLine("Process name: " + Process.GetCurrentProcess().ProcessName);
            Assert.Equal(5, 3);
        }
    }
}

for your custom process you need to write a few hooks so look in the project to get the details on how to do this. 对于您的自定义进程,您需要编写一些钩子,因此请查看项目以获取有关如何执行此操作的详细信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM