cxxtest套件可以在运行时动态扩展吗?
我希望使用其他测试项目动态扩展我的 CxxTest Suite ,但我发现所有测试场景必须在编译时可用(硬编码)。
我的场景是,我有一个相当庞大的 C++ 类,有 20 多个方法需要测试。此类需要针对 40 多个不同的数据集进行测试。这些数据集是通过类构造函数获得的,并通过参数进行控制。
我的主要目标是避免为不同的数据集重写相同的 20 个测试用例。我想使用包含数据集列表的控制文件,并为同一测试套件创建不同的装置。
Q1)如何动态(在运行时)向测试套件添加更多测试?
Q2) 可以在运行时动态添加灯具吗?是否有更好的测试套件允许动态夹具?
Q3)这是 TDD 技术避免的事情吗?任何人都可以很好地总结 TDD 技术。
谢谢,
——J·乔根森——
I wish to dynamically extend my CxxTest Suite with additional test items, but am finding that all the testing scenerios must be available (hard-coded) at compile time.
My scenario is that I've got a fairly bulky C++ class that has 20+ methods to be tested. This class needs to be tested for 40+ DIFFERENT data sets. These data sets are obtained via the class constructor, controlled via parameters.
My primary objective is to avoid re-writing the same 20 test cases for the different data sets. I would like to use a control file that contains the list of data sets, and just create different fixtures for the same test suite.
Q1) How does one dynamically (at run time) add more tests to the testing suite?
Q2) Can one dynamically add fixtures at run time? Is there a better testing suite that allows for dynamic fixtures?
Q3) Is this something that the TDD technique avoids? Anyone got a good summary of the TDD Technique.
Thanks,
-- J Jorgenson --
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
实际上没有任何直接的方法可以做到这一点。测试数量是在编译之前运行
cxxtestgen
时确定的。它会解析您的文件并查找以test
开头的方法名称。它还会查找TestSuite
后代并生成代码来实例化每个后代一次。您可以在每个测试套件上编写一个createSuite
函数以通过参数传递给套件的构造函数,但您仍然只能返回一个对象。您可以修改构建设置以调用测试程序 40 次不同的时间,每次在命令行上传递不同的参数。该计划的问题在于 CxxTest 生成的默认
main
不接受命令行参数。您需要提供自己的实现来检查参数,然后调用正常的测试运行程序。像这样的事情:要使用该功能,请在运行
cxxtestgen
时省略--error-printer
选项,添加
文件末尾,并使用--template
选项生成测试程序。但只要您编写自己的
main
,您也可以尝试在那里解析数据集文件,然后多次调用测试运行程序。像这样的东西:There's not really any direct way to do it. The number of tests is determined prior to compile time, when you run
cxxtestgen
. It parses your files and finds method names starting withtest
. It also findsTestSuite
descendants and generates code to instantiate each one once. You can write acreateSuite
function on each of your test suites to pass parameters to the suite's constructor, but you're still limited to returning just one object.You could modify your build setup to invoke the test program 40 different times, passing a different parameter on the command line each time. The wrinkle in that plan is that the default
main
generated by CxxTest doesn't accept command-line parameters. You'll need to provide your own implementation that checks parameters and then invokes the normal test runner afterward. Something like this:To use that function, omit the
--error-printer
option when you runcxxtestgen
, add<CxxTest world>
at the end of the file, and use the--template
option to generate your test program.But as long as you're writing your own
main
, you might try parsing your data-set file there, too, and then invoking the test runner multiple times. Something like this: