如何使用带有 Visual studio 的 XUnit 对远程进程中的代码 运行 进行单元测试

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

我们正在为 Solidworks CAD 系统编写插件。编写插件涉及编译 DLL、注册它然后启动 solidworks。 dll 中的代码可以配置为在 solidworks 启动时立即执行。

我想做的是制作一个特殊的 DLL,以便它从 visual studio 运行一系列单元测试或单个单元测试,并将结果报告回标准中的 visual studio方式。

我们很乐意使用标准 visual studio 测试或 resharper 测试系统。

是否可以编写单元测试系统的扩展来实现这一点。如果是这样,这有多难实现。也许有些扩展已经为其他需要测试的插件类型环境做了类似的事情。

我们为 XUnit 编写了一个插件来解决这个问题

https://github.com/Weingartner/XUnitRemote

使用上述方法的特定解决方案用于单元测试 solidworks

https://github.com/Weingartner/SolidworksAddinFramework

带有示例自定义的示例测试 事实

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);
        }
    }
}

对于您的自定义流程,您需要编写一些挂钩,因此请查看项目以获取有关如何执行此操作的详细信息。