当我运行(视窗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 –