1

So, I've been developing a few programs for AutoCAD 2005, and I've been constantly running into problems--specifically, I've been working on a program that needs to draw lines based on absolute angles ("azimuths") and distances, converting from a special input format to degrees to radians and back, and, like many other programmers, my code has gotten especially bulky and buggy; I've been stuck for almost a week and a half for a program/script that should've taken about three or four days.

I've been thinking about implementing a testing framework for making development much smoother, but unlike other languages, I'm working in a language that supposedly has absolutely no libraries for it and, even better, it's a embedding scripting environment.

I have a few ideas about how the design might work out, but I need to explain a few things:

Executing commands/AutoLISP background

Most of the programs I write are in the form of console-like commands, much like a shell. For example, say I write a function x. In AutoLISP, it's expressed as (the slash is also literally there): (defun x (arguments / local variables) body of function). To make it exposed to the console, I would need to change the name from x to C:x.

So, most of my testing must be done directly from the console; I tend to avoid the inbuilt Visual Lisp editor in AutoCAD because it seems to be disjointed from the actual working environment that the program will most likely be used in, and it doesn't seem to have an actual debugger. So, I frequently have to use (print "string") or other methods to debug my code.

Ideas/Thoughts/Questions

1. What types of functions might I want to expose for a testing framework? I've heard about multiple paradigms myself, such as compile-time testing, asserts, test classes in Java, etc. Should I try to code an assert? Perhaps I should create reflection-using tests?

2. How and where might I want to inject tests? I've thought about writing a different function and turning all local variables into globals to expose it to a possible testing context, but I'm still unsure of how I might want to do this. AutoLISP is lacking in regular Lisp macros, I believe, but I think it still has very nice reflection capabilities, so it is possible for me to actually feed in commands to the console in order to do things. I feel that an external, non-intrusive framework would make the most sense, but I'd like to get a more experienced answer on this.

4

1 回答 1

1

基本功能:使用相同的输入,系统提供相同的输出。

有用的功能:断言。给定测试代码中的一些设置,然后您运行要测试的程序的一部分,并对输出进行断言。如果所有断言都符合预期,则打印一些最少的内容。如果断言失败,请打印更详细的内容,以帮助追溯出了什么问题。

增量功能。如果你的测试有东西偷偷摸摸,你必须手动找到一个错误,编写一个下次覆盖该错误的测试。

持续的功能。 每次提交到您的源代码控制系统时,至少运行一次测试。如果失败很常见但测试本身很快,它们可以作为 presubmit 运行,或者如果失败很少但测试很慢,它们可以作为 postsubmit 运行。

于 2015-06-26T03:25:16.400 回答