我正在研究基于testNG和ANT的框架。
在build.xml中,我们有:
<delete dir="${test.output}${file.separator}tenantV3Management-cli"/>
<testng classpathref="jars.classpath"
outputdir ="${test.output}${file.separator}tenantV3Management-cli"
haltOnfailure="false"
listeners="com.oracle.common.CustomReporter"
testnames="tenantV3Management-cli">
<classpath location="${target.test.classes.dir}"/>
<classpath refid="jars.classpath" />
<sysproperty key="tempFileLoc" value="${code.build.tempfiles}${file.separator}"/>
<xmlfileset dir="${basedir}" includes="config${file.separator}settingsCLI.xml"/>
</testng>
</target>
在常量.java中,我使用了:
public static boolean isSim3_1Tests=false;
public static void main(String[] args) {
String testProp = "SIMV3.1";
Properties sysProps = System.getProperties();
testProp=sysProps.getProperty(testProp);
if (testProp.equals(false)) {
isSim3_1Tests = false;
} else {
isSim3_1Tests = true;
}
}
我的TestClass.java正在扩展常量.java我的测试用例是这样的:
@Test(groups = {"tenantV3ManagementTest"}, timeOut = 100000)
public void testUpgradeTenant() throws IDMMultiTenancyException {
System.out.println("isSim3_1Tests="+Constants.isSim3_1Tests);
...
}
在这里,当调用测试用例时,isSim3_1Tests结果为假,而我在其超类常量的 main() 中将其设置为 true.java
请建议,为什么会发生这种情况以及如何纠正此问题?我被困在上面,任何帮助将不胜感激。
您实际上从未从sysProps
中查找任何属性。您只需将字符串键(应声明为常量)与 Boolean.FALSE
进行比较,后者将始终为 false。
编辑:您现在正在从Properties
对象中抬头,但结果是一个String
,它永远不能等于Boolean.FALSE
。而不是你拥有的冗余(和错误)结构,使用类似commons-lang的BooleanUtils
Constants.isSim3_1Tests = BooleanUtils.toBoolean(testProp); // and "Constants" is a bad name