public abstract class TestBase{
protected EnvironmentDetails envdetails;
@BeforeTest(alwaysRun = true)
@Parameters({ "envOld", "envNew", "env", "region", "prodcount", "unixuser", "unixpasswd", "mmPortOld", "mmPortNew" })
public void initialize(@Optional("xyz4") String envOld, @Optional("xyz4") String envNew, @Optional("xyz4") String env, @Optional("All") String region,
@Optional("5") String prodcount, @Optional("") String unixuser, @Optional("") String unixpasswd, @Optional("6300") String mmPortOld,
@Optional("6300") String mmPortNew) throws SQLException {
//Populate envdetails
//LOG envdetails
}
}
public class myTest extends TestBase{
@Test(threadPoolSize = 1, invocationCount = 1, groups = { "usersort", "regression" }, dataProvider = "sortingDataProvider")
public void sortTest(final String region, String mmUrl, String servletUrl) {
//LOG envdetails
}
@DataProvider(name = "sortingDataProvider", parallel = false)
public Object[][] provider(Method method) {
Object[][] data = null;
//populate data
return data;
}
在上面的代码中,我在 @BeforeTest 中初始化了对象'envdetails',当我记录对象时,我发现它已正确填充。现在,当我尝试从sortTest方法访问它时,对象 envdetails中的每个实例变量在一次执行中为空,而在其他执行中填充显示,保持代码库和执行参数通过maven不变。这是某种线程问题,还是我犯了一些重大错误。