与第三方软件API的软件(AutoCAD)单元测试的最佳做法 [英] Best practices with Unit testing on Third Party software API's (AutoCAD)

查看:200
本文介绍了与第三方软件API的软件(AutoCAD)单元测试的最佳做法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在开发一种在AutoCAD中使用的应用程序。
基本上,我们创建一个类库项目,并用命令(NETLOAD)加载在AutoCAD中.dll文件。

We are developing applications for use within AutoCAD. Basically we create a Class Library Project, and load the .dll in autoCAD with a command (NETLOAD).

由于这样,我们可以使用的命令,调色板,用户控件,窗体等...

As so, we can use commands, "palettes", user controls, forms etc...

AutoDesk公司通过一些DLL的提供了一个API,在他们的程序目录中运行。
当引用这些dll的你只能调用DLL的在运行时加载在AutoCAD您的应用程序(这是欧特克许可安全性)。

AutoDesk provides an API through some dll's, running in their program directory. When referencing these dll's you can only call the dll's at runtime while loading your app in AutoCAD (This is a licensing security from AutoDesk).

对于我们来说,在开发,这不是一个问题,我们需要的AutoCAD的环境中以可视的测试,所以我们只设置调试属性,使他们开始的acad.exe并与在ACAD脚本加载我们的DLL .exe文件的参数。

For us, while developing, this is not a problem, we need to visually test within the context of AutoCAD, so we just set the Debug Properties so that they start acad.exe and load our dll with a script in the acad.exe parameters.

问题是,试图单元测试时,我们的code,NUnit的或MSTest的不从AutoCAD的范围内运行,他们也可以不启动它。
存在一个称为加利奥工具,至极提供与AutoCAD一个接口,以便它能够具有命名管道通过IPC运行单元测试。

The problem is, when trying to unit test our code, NUnit or mstest are not running from within the AutoCAD context and they also cannot start it. There exist a tool called Gallio, wich has provided an interface with AutoCAD, so that it can run Unit test through IPC with Named Pipes.

然而,这种解决方案是,对我来说,太麻烦了。我希望能够快速编写测试,而无需离开我心爱的IDE。

However, this solution is, for me, too much of a hassle. I want to be able to quickly write tests without having to leave my beloved IDE.

那么,是什么,从一个好设计视图将是一个很好的办法解决这个问题?我想我基本上需要一个可测试codeBase的至极没有引用AutoCAD的dll的和非可测试的,做引用不可测的AutoCAD dll的。

So, what, from a "good design view" would be a good approach to this problem? I'm thinking I would basically need a testable codebase wich is not referencing the AutoCAD dll's and a non-testable that does references the untestable AutoCAD dll's.

我敢肯定有办法得到这个工作:(IOC,DI,适配器模式,。)我只是做深入的不是这些原则,因此我不知道至极的路线,将最适合我的目的和目标。

I'm sure there are ways to get this to work: ( IOC, DI, Adapter Pattern,. .) I just don't these principles in depth and thus I don't know wich route will best suit my purposes and goals.

推荐答案

第一步是分流你的code,对于它需要AutoCAD和这是真正独立的部分零件。对于独立的部分创建单元测试你通常会。

The first step is to triage your code for parts which need AutoCAD and parts which are really independent. Create unit tests for the independent parts as you usually would.

有关的其他部分,你需要它们的行为如AutoCAD实体模型。让他们尽可能的简单(例如,刚刚返回的方法的正确答案没有做任何的计算)。现在,你需要几套类:

For the other parts, you need mockups which behave like AutoCAD. Make them as simple as possible (for example, just return the correct answers in the methods without doing any calculations). Now, you need several sets of classes:


  1. ,你的code使用实现的东西一组接口(例如,加载一个图)。

  1. A set of interfaces which your code uses to achieve something (for example, load a drawing).

一组实现了该组的调用其中的AutoCAD中的DLL接口。

A set of implementations for said set of interfaces which call the AutoCAD dlls.

一组类而尝试的AutoCAD范围内的实现。只要创建一个小的UI与一对夫妇的按钮,你可以运行这个code。它是用来安慰自己,你的样机做正确的事。登录方法参数和结果的一些文件,所以你可以尝试的AutoCAD如何响应。如果样机休息,你可以使用这个code,以验证AutoCAD的东西是做和开发原型时,你可以使用它作为一个参考。

A set of classes which try the implementations within the context of AutoCAD. Just create a small UI with a couple of buttons where you can run this code. It is used to reassure yourself that your mockups do the right thing. Log method parameters and results to some file so you can try how AutoCAD responds. If a mockup breaks, you can use this code to verify what AutoCAD is doing and you can use it as a reference when developing the mockups.

当你知道AutoCAD中如何响应,创建实体模型。在测试中,创造他们想要的结果(和错误,因此您可以测试错误处理,太)。所以,当你有布尔loadDrawing(文件名),创建一个样机返回真正作为文件名 exists.dxf 做别的事情。

When you know how AutoCAD responds, create the mockups. In your tests, create them with the desired results (and errors, so you can test error handling, too). So when you have boolean loadDrawing(File filename), create a mockup which returns true for the filename exists.dxf and false for anything else.

使用工厂或DI告诉你的应用程序code使用哪种实现。我往往有很多公共领域,我只是存储的对象使用一个大的全球配置类。我可以在一开始设置的,它的速度快,这很容易理解。如果你需要在运行时创建的对象,然后把在配置类生成的对象为你的工厂,所以你可以换出来。

Use a factory or DI to tell your application code which implementation to use. I tend to have a big global config class with a lot of public fields where I simply store the objects to use. I can set this up in the beginning, it's fast, it's easy to understand. If you need to create objects at runtime, then put factories in the config class which generate the objects for you, so you can swap them out.

这篇关于与第三方软件API的软件(AutoCAD)单元测试的最佳做法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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