问题
I read its NOT best practice to write dependent test scenarios. But what if an application is heavily data-driven and manipulates (creates, multiple update flows, logically deletes) data. Basically, we want to minimize:
- Test data creation for each dependent scenario (ex. updates need creation of data first)
- re-execution of steps
- Overall test suite execution time
Question: In order to control the execution of threads, can I can extend Karate core classes which handles @parallel=false and add custom code which considers 'Depends on Scenario' ? Is there a better/alternate design? Please suggest.
Example:
- Scenario1 : Create T1, T2 [Parallel]
- Scenario2 : Create T3 [Parallel]
- Scenario3 : Create R1(relationship between T1 and T2)which updates T1, T2 [Sequential: wait until 1]
- Scenario4 : Create R2(relationship between T1 and T3) which updates T1, T3 [Sequential:wait until 1,2]
- Scenario5 : Delete R1 which updates T1,T2 [Sequential: wait until 1,3]
- Scenario6 : Delete T1 which deletes R1,R2 [Sequential: wait until 1,4,5]
回答1:
There is no "magic" you have to either:
a) write "flows" that set up data at the start (this is what a Background
is for) and test all the expected conditions
b) write tests that are "smart" and are immune to the starting state of the database. for example, do a GET, see how many customers already exist, and then calculate expected count. but this can be affected by parallel threads unless each thread is designed to work on a different set of customers (partition by e.g. organization)
As a reminder, read this: https://github.com/intuit/karate#script-structure
来源:https://stackoverflow.com/questions/62494745/how-to-design-data-driven-dependent-scenarios-testing