C++ 的 DbUnit?

发布于 2024-07-13 23:59:00 字数 293 浏览 5 评论 0原文

我们正在 Linux 下使用 C++ 进行开发,并即将设置自动化测试。 我们打算使用 CppUnit 或 CxxTest 等测试框架。 我们使用 Ant 来构建软件,并且还将使用它来运行测试。

由于某些测试将涉及数据库访问,因此我们正在寻找一种工具或框架来简化数据库中准备和清理测试数据的任务 - 就像 Java 世界中的 DbUnit(JUnit 扩展)一样。

另一种选择可能是使用实际的 DbUnit - 可以使用 Java VM。 利用 DbUnit 的 Ant 任务似乎是最有前途的。 欢迎任何相关领域报告!

We're developing in C++ under Linux and about to set up automated tests. We intend to use a testing framework like CppUnit oder CxxTest. We're using Ant to build the software and we will also use it to run the tests.

As some tests are going to involve database access, we are looking for a tool or framework which facilitates the tasks of preparing and cleaning up test data in the database - just like DbUnit (a JUnit extension) in the Java world.

Another option may be to employ the actual DbUnit - a Java VM is available. Making use of DbUnit's Ant task seems to be most promising. Any related field reports are welcome!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

泛泛之交 2024-07-20 23:59:01

我想你有自己的 C++ api 来使用 DB。
如果是这样,您最好自己完成所有数据库准备工作。 在这种情况下,您还将测试您的数据库 API。

I suppose you have your own C++ api to work with DB.
If it is true, you'd better to do all your DB preparation by your own. In that case you will test your DB API as well.

傲影 2024-07-20 23:59:01

由于似乎没有类似 DbUnit 的 C++ 开发工具,因此我们构建了自己的一个小框架。 基本上,它是一个适配器,用于从 C/C++ 测试运行程序中调用实际的 DbUnit 操作。 它利用 DbUnit 提供的 Ant 任务

我们定义了一些宏,例如 TS_DB_INSERT(filename) ,它调用 system("ant -Ddb.dataset=filename db.insert") 等。

在本例中,db.insert 是一个 Ant 目标,它执行 DbUnit 任务,对数据库执行 INSERT 操作。 filename 引用包含要插入的数据的 XML 数据集。
还有一个包装 DbUnit compare 的断言宏。

测试用例可能如下所示:

void testDatabaseStuff
{
    TS_DB_INSERT("input.xml");

    TestedClass::doSomething();

    TS_DB_ASSERT("expected.xml");
}

As there seems to be no DbUnit-like tool for C++ development, we've built a little framework of our own. Basically it's an adaptor for calling actual DbUnit operations from within C/C++ testrunners. It makes use of the Ant tasks provided by DbUnit.

We defined some macros like TS_DB_INSERT(filename) which call system("ant -Ddb.dataset=filename db.insert") and the like.

In this case, db.insert is an Ant target which executes a DbUnit task performing an INSERT operation on the database. The filename references an XML dataset containing the data to insert.
There's also an assertion macro which wraps a DbUnit compare.

The test case might look like this:

void testDatabaseStuff
{
    TS_DB_INSERT("input.xml");

    TestedClass::doSomething();

    TS_DB_ASSERT("expected.xml");
}
亣腦蒛氧 2024-07-20 23:59:00

I would recommend boost unit testing. You would probably have to use the setup and teardown to manually clean up the database. Of course, you could build your own C++ DbUnit in ODBC. IF you do let me know because I could use this as well!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文