TestNG官方文档 https://www.jianshu.com/p/d430c78016e6
TestNG-参数传递几种方式 https://blog.csdn.net/xueningyang555/article/details/88871426
如下,向监听器,类等传递参数可以通过如下
@BeforeSuite @Parameters({"baseurl","account","password"}) public void beforeSuite(String baseurl,String account,String password ){ this.baseurl=baseurl; this.account=account; this.password=password; }
@Listeners(MyListener.class) @Test(testName = "MyTest") public class MyTest { @Parameters({ "apiurl", "useratorg", "password", "catalogname", "vapptemplatename", "vappusr", "vapppwd", "jobid" }) @BeforeClass public void setUpConnectionProperties(String apiUrl, String userAtOrg, String password, String catalogName, String vAppTemplateName, String vAppUsr, String vAppPwd, String jobId) { ...} }
public class MyListener extends TestListenerAdapter { @Override public void onStart(ITestContext testContext) { jobId = testContext.getSuite().getParameter("jobid"); super.onStart(testContext); } }
@BeforeMapping 用法
public interface MappingCustomizer { @BeforeMapping void calledBefore(BaseEntity source); @AfterMapping void calledAfter(BaseEntity source, @MappingTarget BaseDTO target); } @Mapper( uses = { ..., MappingCustomizer.class } ) public interface PersonMapper { ... } public class PersonMapperImpl implements PersonMapper { @Inject private MappingCustomizer mappingCustomizer; @Override public PersonDTO entityToDTO(Person source) { mappingCustomizer.calledBefore(source); // because Person extends BaseEntity, and the @BeforeMapping method is applicable PersonDTO personDto = new PersonDTO(); // ... property mapping mappingCustomizer.calledAfter(source, personDto); // because the source parameters and the target type are applicable return personDto; }