TestNG - 在测试类之间共享状态 [英] TestNG - sharing state between test classes

查看:37
本文介绍了TestNG - 在测试类之间共享状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 测试类套件我通过 testng.xml 文件运行.这工作正常.所有测试都是串行运行的,因此没有并行执行的障碍.

I have a testng suite of test classes that I am running via a testng.xml file. This works fine. All tests are run serially, so no parallel-execution hurdles.

我现在的目标是获取由一个测试类中的测试方法生成的状态(例如,由数据库插入生成的 customerId 主键值)并将其传递给另一个测试类,以便第二个类中的测试方法可以根据该共享状态采取进一步的操作(例如,使用第一个类中的 customerId 值查找刚刚插入的客户).

My goal now is to take state that was generated by the test methods in one test class (e.g., a customerId primary key value generated by a database insert) and pass it along to another test class, so that the test methods in that second class can take further action based on that shared state (e.g., look up the just-inserted customer using the customerId value from the first class).

在单个类中的测试方法之间共享状态很容易,当然,通过类成员变量,但我不知道如何在测试类之间共享它.

It's easy to share state between test methods in a single class, of course, via class member variables, but I don't see how to share it across test classes.

推荐答案

使用工厂来创建存储库.存储库存储有趣的测试状态"属性.

Use a factory to create a repository. The repository stores "interesting test state" properties.

  TestRepository tr = TestRepositoryFactory.getInstance();
  ...
  tr.store("test13.PKID", pkid.toString());

然后在您后续的代码中,重复对工厂的调用,然后获取值:

and then in your subsequent code, repeat the call to the factory and then get the value:

  String spkid = tr.get("test13.PKID");

这篇关于TestNG - 在测试类之间共享状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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