Java 当我运行testNG类时,由于无法实例化类而出现错误
请任何人帮我解决这个问题Java 当我运行testNG类时,由于无法实例化类而出现错误,java,eclipse,rest,rest-assured,Java,Eclipse,Rest,Rest Assured,请任何人帮我解决这个问题 org.testng.TestNGException: Cannot instantiate class com.abcd.apitesting.bvt.accBVT at org.testng.internal.ObjectFactoryImpl.newInstance(ObjectFactoryImpl.java:40) at org.testng.internal.ClassHelper.createInstance1(ClassHelper.java:377)
org.testng.TestNGException:
Cannot instantiate class com.abcd.apitesting.bvt.accBVT
at org.testng.internal.ObjectFactoryImpl.newInstance(ObjectFactoryImpl.java:40)
at org.testng.internal.ClassHelper.createInstance1(ClassHelper.java:377)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
Caused by: java.lang.RuntimeException: Unable to load properties file:/configure.properties
at com.thed.zeeapitesting.util.Configure.init(Configure.java:26)
在eclipse中,当我运行testNG类时,会出现如下错误
我的代码是
import org.testng.annotations.BeforeClass;
import com.jayway.restassured.RestAssured;
import com.jayway.restassured.builder.RequestSpecBuilder;
import com.jayway.restassured.specification.RequestSpecification;
import com.abcd.abcapitesting.action.Factory;
public class Trigger {
protected static boolean isInit = false;
protected static IInfoAction inf = null;
protected static String Version = null;
protected static String sessionId = null;
public static boolean initializeInfoAPI = true;
public Trigger() {
init();
}
public static void init() {
if (isInit) {
return;
}
Configure configure = new Configure();
Version = Configure.getValue("VERSION");
Factory.init(Version);
if (initializeInfoAPI) {
inf = Factory.getInfoActionInstance();
}
isInit = true;
}
@BeforeClass
public void setup() {
RestAssured.baseURI = Configure.getValue("abc_BASE_URL");
RestAssured.port = Integer.parseInt(Configure.getValue("abc_PORT"));
RestAssured.basePath = Configure.getValue("abc_BASE_PATH");
sessionId = inf.createSessionId(RestUtil.setRequest()).asString();
}
}
我的testNG类如下所示
public class abcBVT extends Trigger {
public void Trigger() {
initializeInfoAPI = true;
}
@Test(priority = 1, enabled = enableAll)
public void bvt1_getManifest() {
JSONResponseBody = inf.getManifest(RestUtil.setRequest(sessionId));
status = inf.validateManifest(JSONResponseBody);
if (status) {
logger.info("getManifest Executed Successfully...!");
}
}
}
我被阻止了。阅读整个stacktrace:问题的根源在于
Configure.init(Configure.java:26)
:无法加载属性文件:/Configure.properties
以前它是工作的,我在配置文件中没有做任何更改,直到某些内容必须发生更改。您可以尝试调试代码,并找出加载属性时出现的问题我没有得到…加载属性文件configure.path=“/configure.properties”时一切正常;System.out.println(路径);prop=Util.loadProperties(Configure.path);如果(prop==null){抛出新的RuntimeException(“无法加载属性文件:“+Configure.path”);}