java数据驱动集成测试工具

发布于 2024-10-15 10:34:00 字数 565 浏览 8 评论 0原文

我面临着我认为是一个常见问题,但我还没有找到太多讨论或现有工具来解决它。我正在尝试建立一个集成测试系统(已经拥有一套强大的单元测试),该系统支持 QA 提交输入数据和预期结果(理想情况下以平面文件的形式),可以从标准化的 junit 类运行。

我计划使用 junit @Paramaterized 注释在这里推出自己的版本。我想象每组数据和结果都有一个控制文件,并且所有控制文件都放在一个目录中。参数生成器方法将扫描该目录并返回这些文件的列表。然后,测试构造函数将读取该文件并设置输入数据和预期结果。

在开始写这篇文章之前,我想看看是否已经存在可以完成此类操作的工具,如果没有,请就我提出的解决方案获取一些意见。

该应用程序本身是一个纯粹的后端 ETL 类型工具,它从多个不同格式的输入文件中获取数据并在数据库中生成结果。我已经进行了一些静态集成测试,这些测试使用内存数据库中的 Derby 来检查琐碎输入数据的结果,并且我计划使用类似的系统来确认此处的数据。预期结果将采用(key_value,column,expected value)三元组的形式。我想使用 junit 来连接我们的其余测试和结果报告基础设施。

I'm facing what I would think is a common problem, but I haven't found much discussion or existing tools to address it. I am trying to set up an integration test system (already having a strong suite of unit tests) which supports QA submitting input data and expected results (in the form of flat files, ideally) which can be run from a standardized junit class.

I have a plan to roll my own here using the junit @Paramaterized annotation. I'm imagining each set of data and results having a control file, and all control files being placed in one directory. The parameter generator method would scan this directory and return a list of these files. The test constructor would then read this file and set up the input data and expected results.

Before I start writing this, I wanted to see if there already existed tools to do this type of thing, and if not, get some opinions on the solution I am proposing.

The application itself is a purely back end ETL type tool, which takes data from several input files in various formats and produces results in a database. I already have some static integration tests which use a Derby in memory database to check the results for trivial input data, and I plan to use a similar system to confirm the data here. Expected results would be in the form of (key_value, column, expected value) triples. I want to use junit in order to tie into the rest of our testing and result reporting infrastructure.

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

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

发布评论

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

评论(2

葮薆情 2024-10-22 10:34:00

查看 Spock,这是一个基于 Groovy 的测试框架,对数据驱动测试提供强大支持。 Spock 专为测试 Java(和 Groovy)代码而设计,并且与 JUnit 完全兼容(事实上,Spock 测试是使用 JUnit 运行的)。请参阅此处了解从数据库提取数据的简单示例测试。

总的来说,你的计划对我来说听起来很合理,也可以用普通的 JUnit 和 @Parameterized 来实现。 Spock 和 Groovy 可以让您的生活更轻松。例如,在 Groovy 中处理文本文件和数据库比在 Java 中容易得多。

免责声明:我是 Spock 的创造者。

Have a look at Spock, a Groovy-based testing framework with strong support for data-driven testing. Spock is designed for testing Java (and Groovy) code, and is fully compatible with JUnit (in fact, Spock tests are run with JUnit). See here for a simple example test that pulls data from a database.

In general, your plan sounds reasonable to me, and can also be realized with plain JUnit and @Parameterized. Spock and Groovy can make your life easier though. For example, working with text files and databases is much easier in Groovy than in Java.

Disclaimer: I'm the creator of Spock.

ぽ尐不点ル 2024-10-22 10:34:00

我自己更喜欢斯波克。但我确实看到有一个 JUnitParams 框架比直接的 JUnit 参数化测试更具可读性:

https:// github.com/Pragmatists/junitparams

可以在以下位置找到精彩的描述:

https://weblogs.java.net/blog/johnsmart/archive/2014/07/23/data-driven-unit-testing-java

对于其他点击这个问题……

I prefer Spock myself. But I do see that there is a JUnitParams framework out there that is much more readable than straight JUnit parameterized tests:

https://github.com/Pragmatists/junitparams

A great description can be found at:

https://weblogs.java.net/blog/johnsmart/archive/2014/07/23/data-driven-unit-testing-java

For others hitting this question....

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