【发布时间】:2009-10-19 01:05:23
【问题描述】:
我目前正在开发我的一个小项目,该项目以动态方式生成 SQL 调用以供其他软件使用。事先不知道 SQL 调用,因此我希望能够对生成 SQL 的对象进行单元测试。
您是否知道如何做到这一点的最佳方法?请记住,没有办法知道所有可能生成的 SQL 调用。
目前我唯一的想法是使用正则表达式从数据库创建已接受 SQL 的测试用例,并确保 SQL 能够编译,但这并不能确保调用返回预期结果。
已编辑:添加更多信息:
我的项目是 Boo 的扩展,它允许开发人员用一组属性标记他的属性。此属性用于标识开发人员希望如何将对象存储在数据库中。例如:
# This attribute tells the Boo compiler extension that you want to
# store the object in a MySQL db. The boo compiler extension will make sure that you meet
# the requirements
[Storable(MySQL)]
class MyObject():
# Tells the compiler that name is the PK
[PrimaryKey(Size = 25)]
[Property(Name)]
private name as String
[TableColumn(Size = 25)]
[Property(Surname)]
private surname as String
[TableColumn()]
[Property(Age)]
private age as int
好主意是生成的代码不需要使用反射,而是会在编译时添加到类中。是的,编译需要更长的时间,但根本不需要使用反射。我目前的代码正在生成在编译时返回 SQL 的所需方法,它们被添加到对象中并且可以被调用,但我需要测试生成的 SQL 是否正确:P
【问题讨论】:
标签: database unit-testing testing code-generation