测试策略:生成XML文件

发布于 2024-08-07 22:40:06 字数 388 浏览 6 评论 0原文

我正在编写几个生成 xml 文件的类。 (目前细节可能并不重要)。

我想知道最好的测试策略是。

  • 我不想重写 xml 生成代码只是为了比较输出,当我可以将文件写入磁盘并在某些里程碑上进行比较时(xml 规范不会经常更改,例如每两个更改一次或两次)年)
  • 我更感兴趣的是测试架构的行为而不是吸气剂和吸气剂。 setters

想到的选项:

  • 在测试环境中重建 xml 文件并比较字符串表示形式
  • 手动检查结果(写入文件等)
  • 在测试环境中重建内存中的 xml 文件并比较内存中的元素。

如果您知道任何 C++ 和/或 Google Test 库,将获得虚拟奖励。

有想法吗?

I'm writing a couple of classes that generate xml file. (Details probably not important at the moment).

I wondering the best testing strategy is.

  • I don't want to re-write the xml generation code just to compare the output, when I could write the file to disk and compare it at certain milestones (the xml spec won't change often, like once or twice every couple of years)
  • I'm more interested in testing the behaviour of the architecture instead of the getters & setters

Options that come to mind:

  • rebuilding the xml file in the testing environment and comparing the string representations
  • manually checking the result (writing to file, etc)
  • rebuilding the xml file in memory in the testing environment and comparing the in-memory elements.

Virtual Bonus if you know any libraries for C++ and/or Google Test.

Ideas?

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

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

发布评论

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

评论(4

墟烟 2024-08-14 22:40:07

您是否考虑过使用 XSD 并根据 XSD 验证您的 XML?您没有提到您正在测试的是内容还是结构(可能两者都是)。
如果通过验证,它将测试 XML 的结构是否符合所需的结构。

Have you considered using XSD's and validating your XML to the XSD? You didn't mention if it was content or structure you were testing for (probably both).
If it validates, it will test the structure of the XML will conform to the required structure.

故事灯 2024-08-14 22:40:07

过去,我采用了两种方法:

将 xml 文件与测试文件中以字符串形式存储的结果进行比较。这很容易实现,除非您想要生成 xml 文件的变体用于测试目的,否则字符串比较方法可以正常工作。

如果您有 xml 文件编写器和读取器,您可以将原始结果与往返结果进行比较。

我同意你的观点,你不应该仅仅为了测试的目的而在测试函数中复制生成文件的逻辑。另外,我会尽力避免写入文件系统的需要——这是对文件系统不必要的依赖,并且可能会导致测试运行速度变慢。

In the past I've approached this two ways:

Compare the xml file against the result stored as a string in the test file. This is easy to implement, and unless you are wanting to generate variations of the xml file for testing purposes, the string comparison method works fine.

In the case where you have a xml file writer and reader, you can compare the original with the round trip result.

I agree with you that you shouldn't replicate the logic to generate the file in the test function, just for the purpose of testing. Also, I would try to avoid the need to write to the file system -- this is unecessary dependence on the file system, and would probably result in slower running tests.

美煞众生 2024-08-14 22:40:07

您可以考虑使用 XML 单元:http://xmlunit.sourceforge.net
它提供了可用于断言相等性的 JUnit 扩展类
XML 文件。

You might consider using XML Unit: http://xmlunit.sourceforge.net.
It provides JUnit extension classes which can be used to assert equality
of XML files.

别忘他 2024-08-14 22:40:07

您可以考虑使用 XML diff 工具。 MSDN 上有一个免费的工具:XML Diff and Patch Tool

我看到您正在寻找 C++ 工具。在这种情况下, libxmldiff 可能更合适。

You might consider an XML diff tool. There is a free one available on MSDN: XML Diff and Patch Tool.

I see you are looking for C++ tools. In that case, libxmldiff might be more suitable.

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