我在 Eclipse 中有一個項目,它是一個WebService項目 REST API,我還在其中添加了另一個項目,Configure Build path -> Add Project并且在我的 API 方法中添加了另一個項目,我正在調用TestNGCreator類,請看下面。基本上這個項目使用 java 中的 jersey 框架創建 REST API,當我調用任何特定方法時,即執行它將調用另一個駐留在另一個項目中的類,我在這個項目的構建路徑中添加了項目,我的其他方法工作正常但是當我我從不同的項目調用方法我有這個錯誤。我是否需要在 POM.xml 或其他地方聲明一些我正在使用此類和此方法的地方我需要通過調用它來運行自動化TestNGCreator.main(null); 我的另一個項目是 javaTestNGCreator類中的自動化項目駐留在自動化項目中。通過調用此方法我需要調用上面的類并且當我這樣做時我收到錯誤。文件:Resource.java @POST @Path("/execute") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public Response executeScript(String data) throws JSONException { ArrayList<Object> testCases = new ArrayList<Object>(); JSONArray jsonArray = new JSONArray(); JSONObject json = new JSONObject(data); String configFile = (String) json.get("ConfigFiles"); String sheetName = (String) json.get("Sheetname"); jsonArray = (JSONArray) json.get("testCases"); for (int i = 0 ; i < jsonArray.length() ; i++) { testCases.add(jsonArray.get(i)); } try { TestNGCreator.main(null); //here i am calling that class main method } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } Response response = null; System.out.println(jsonArray); System.out.println(testCases); return response; }
1 回答

哈士奇WWW
TA貢獻1799條經驗 獲得超6個贊
我在你的 pom 文件中沒有看到 test-ng 依賴項。請添加以下內容并嘗試。
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.10</version>
<scope>test</scope>
</dependency>
添加回答
舉報
0/150
提交
取消