當我運行(視窗7命令行):爲什麼TestNG看到我的包但不是我的課?
C:\其餘應用內的\ src \主\的java \ COM \ myCompany的\應用\試驗>的java org.testng.TestNG的testng.xml
我得到:
=========================================== ====
Suite1 總測試運行:0,失敗:0,跳過:0
======================= ========================
這是當我的testng.xml文件看起來像:
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Suite1" verbose="1" >
<test name="SandBoxTests" >
<packages>
<package name="com.mycompany.app.Test" />
</packages>
</test>
</suite>
我在該包中的類三項測試。
當我改變我的testng.xml文件是:
<suite name="Suite1" verbose="1" >
<test name="SandBoxTests" >
<classes>
<class name="com.mycompany.app.Test.SandBoxTests">
<methods>
<include name="com.mycompany.app.Test.SandBoxTests.TestA"/>
</methods>
</class>
</classes>
</test>
</suite>
我得到的迴應:
[TestNG中] [錯誤] 找不到類路徑中的類:com.mycompany.app。 Test.SandBoxTests
我的類路徑是這樣的:
C:\ REST的應用程序\ LIB \ *; C:\ REST的應用程序的\ src \主\ java中的\ com \ myCompany的\程序\測試\ *
第一個目錄指向我所有包含的.jar文件,包括testng,最後一個目錄包含我嘗試運行測試的類文件的位置。我的testng.xml文件也在那裏。
那麼TestNG怎麼會發現我的包很好,但是看不到我的課?
我的代碼是:
package com.mycompany.app.Test;
import com.mycompany.app.RestMethods;
import com.mycompany.app.Test.TestObjects.AutoCompleteList;
import com.mycompany.app.Test.TestObjects.AutocompleteItem;
import com.mycompany.app.Test.TestObjects.Title;
import com.thoughtworks.xstream.XStream;
import org.apache.http.HttpResponse;
import org.testng.Reporter;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import static org.junit.Assert.assertTrue;
public class SandBoxTests
{ ...
@BeforeClass
public void SetupSandBoxTests() throws Exception
{
}
@Test
public void TestA() throws Exception
{
...
}
...
}
編輯:我更新了我的類路徑中,包括有我的TestNG進行編譯源文件的位置,也包括包含我的testng.xml文件的路徑的根目錄,但沒有任何更改。我說:
C:\ REST的應用程序\出\生產\ MAIN \ *; C:\ REST的應用程序\出\生產\ MAIN \ COM \ HomeAway的\程序\測試\ *
編輯10/25:Maven現在可以正確構建並執行測試,但我仍然無法從命令行獲取testng。爲了讓Maven來運行我的測試,我不得不使用
<includes>
<include>**/*.java</include>
</includes>
代替:
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
http://stackoverflow.com/questions/39942523/unable-to-read-methods-on-class-testng/40329265#40329265 –