简体   繁体   English

数据测试 / REST 保证 / Java 单元测试

[英]Data Testing / REST Assured / Java Unit Testing

So in the past I have worked with rest assured and other java frameworks.因此,过去我曾使用过 rest 和其他 java 框架。

This is more an open ended question in what is the best / modern way to test data either sql / oracle...etc这更像是一个开放式问题,什么是测试数据的最佳/现代方式 sql / oracle ......等

So the basics would be is you need to confirm data in a table is equal to a specific string / int / boolean...etc.所以基础是你需要确认表中的数据等于特定的字符串/int/boolean...等。 The test needs to be able to run via maven or something that can be integrated into a Jenkins type of environment so that it will be run on every build.测试需要能够通过 maven 或可以集成到 Jenkins 类型的环境中的东西运行,以便在每次构建时运行。

What would you suggest is the best way to achieve this any idea or tools that you have used would be welcome.您会建议什么是实现这一目标的最佳方式,您使用过的任何想法或工具都会受到欢迎。

I have searched around and most people are just doing normal unit tests.我四处搜索,大多数人只是在做普通的单元测试。 But if i wanted to test production data that should remain static what would you suggest or are the best practices.但是,如果我想测试应该保留的生产数据 static 你会建议什么或者是最佳实践。

Thanks Flenters谢谢弗伦特斯

Let me present my opinion, hopefully it will clarify some things:发表一下我的看法,希望能澄清一些事情:

First of all, the data testing is really a broad topic, there is no one "silver bullet solution" and one adopted approach.首先,数据测试确实是一个广泛的话题,没有一种“灵丹妙药”和一种采用的方法。

Usually, you can test your DAO code (SQL queries) with the help of a spring testing framework that, among other things provides a way to load some data before the test, run the code that interacts with the database, transaction management, etc.通常,您可以在 spring 测试框架的帮助下测试您的 DAO 代码(SQL 查询),除其他外,该框架提供了一种在测试前加载一些数据、运行与数据库交互的代码、事务管理等的方法。

This kind of test is not a unit testing, it falls into the category of an integration testing, which can be easily supported by maven/Gradle, be run from jenkins as a part of the pipeline.这种测试不是单元测试,它属于集成测试的范畴,maven/Gradle 可以轻松支持,作为管道的一部分从 jenkins 运行。

There is also a tool called DbUnit that also works in this domain.还有一个名为DbUnit的工具也适用于该领域。

However, this is not the same as "testing the data".但是,这与“测试数据”不同。

Let me ask you a question, many questions actually, which all are boil down to: what exactly do you want to test?让我问一个问题,实际上有很多问题,都归结为:你到底想测试什么? The fact that the data is consistent?数据一致的事实? Do you have constraints in the database, do you rely on them?你在数据库中有约束,你依赖它们吗? Or avoid them and stuff like indices for performance reasons or any other reason that can be justified by your use case?还是出于性能原因或您的用例可以证明的任何其他原因避免使用它们和诸如索引之类的东西?

Do you want to populate the data during the test?您想在测试期间填充数据吗? How will it influence the data that already exists in production?它将如何影响生产中已经存在的数据?

Do you plan to use transactions in the tests?你打算在测试中使用事务吗? For example spring testing framework that I've mentioned above is able to automatically open a "test transaction" before the test, and after the test execute an artificial rollback regardless the actual result of the test.比如我上面提到的spring测试框架可以在测试前自动开启一个“测试事务”,测试后不管测试的实际结果如何,都会进行人工回滚。 This way it guarantees that all the changes done during the test will rollback and the data won't be changed after the test, but the question is open?这样可以保证测试期间所做的所有更改都会回滚,并且测试后数据不会更改,但是问题是开放的吗?

Do you plan to test the schema changes over-time.您是否计划随着时间的推移测试架构更改。 Usually, it's possible to change schema with new versions of the product.通常,可以使用产品的新版本更改架构。 In this field the tools like liquidbase or flyway shine.在这个领域,像liquidbase或flyway这样的工具大放异彩。 For example, Flyway provides a notion of "atomic" migration and you basically can apply a series of migrations "transforming" the schema to the desired state.例如,Flyway 提供了“原子”迁移的概念,您基本上可以应用一系列迁移将架构“转换”到所需的 state。 It doesn't fall into the category of testing tools though, although you can run this migration thing from maven if you wish.虽然它不属于测试工具的类别,但如果您愿意,您可以从 maven 运行此迁移。

As you see, these questions do not have "generally correct" answers, different projects have different needs.如您所见,这些问题没有“普遍正确”的答案,不同的项目有不同的需求。 So bottom line if you want to discuss a specific approach that you think is applicable to your product - you'll welcome to provide more technical details, but other than that - all the frameworks/libraries that I mentioned can qualify as tools that you ask about, and still there is a lot of missing information here.因此,如果您想讨论认为适用于您的产品的特定方法,那么底线 - 欢迎您提供更多技术细节,但除此之外 - 我提到的所有框架/库都可以作为您要求的工具关于,这里仍然有很多缺失的信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM