我们能否确定参数化测试何时完成所有动态生成的测试 [英] Can we identify when a parameterised test finished all tests dynamically generated

查看:59
本文介绍了我们能否确定参数化测试何时完成所有动态生成的测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑一个场景. 我正在使用对对象的有效负载字段进行验证的API测试.

Consider a scenario. I'm performing API testing with validations on the payload fields of an object.

我在数据库中准备了前提数据,例如,该数据是有效的DataClass对象. 我将对象提供给ArgumentsProvider,以便通过调整所提供的有效对象的一个​​字段来逐字段生成无效值.

I prepare a prerequisite data in the database which is a valid DataClass Object for example. Post which I provide that object to an ArgumentsProvider to generate field by field invalid values by tweaking one field of the provided valid object.

通常,对于不是Parameterized的其他测试,我可以拆除在afterEachCallBack中为该测试创建的数据,但是,在使用ArgumentsProvider的情况下,我不能在进行所有测试之前将其拆除该特定的测试功能完成,否则在第一次测试之后,如果我将数据拆解(从数据库中删除),则该数据将无法用于下一个测试.

Normally, for other tests which are not Parameterized, I can tear down the data created for the test in afterEachCallBack, however, in case of using ArgumentsProvider I can't tear it down before all tests for that particular test function finish, otherwise after the first test, if I tear the data down (remove from DB) then it's not available for next test.

在某些情况下,我尝试使用Function<DataClass, APIQuery> function,但这使我需要为从ArgumentsProvider

I have tried using Function<DataClass, APIQuery> function in some cases, but this leads me to create a valid data in DB for each iteration of test generated from ArgumentsProvider

是否可以使用TestWatcherTestExecutionListenerExtensions或其他方式来标识具有动态生成函数的函数何时完成并移至下一个函数. 这样,我可以在所有Parameterized测试完成后拆除数据.

Is it possible to identify, using TestWatcher, TestExecutionListener or Extensions or some other way, when the function which had dynamicallyGenerated functions has finished and moved to next function. This way, I can tear down the data after all Parameterized tests have finished.

推荐答案

您有一个选择,就是将参数化测试方法放入它自己的ˋ@ Nestedˋ内部类中,并使用实现ˋAfterAllCallbackˋ的扩展对其进行扩展.

One option you have is to put the parameterized test method into ist own ˋ@Nestedˋ inner class and extend it with an extension that implements ˋAfterAllCallbackˋ.

这篇关于我们能否确定参数化测试何时完成所有动态生成的测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆