自动测试issue-testng异常

时间:2012-10-09 10:44:17

标签: maven testng

我有2个模块都有各自的pom.xmls,我想运行module1的pom.xml并使用它运行一些module2的代码,使用classname在testng.xml中运行。 现在这永远不会工作,我得到一个ClassNotFoundException。 请帮助。

Cannot find class in classpath: com.org.Console1
    at org.testng.xml.XmlClass.loadClass(XmlClass.java:76)
    at org.testng.xml.XmlClass.init(XmlClass.java:68)
    at org.testng.xml.XmlClass.<init>(XmlClass.java:54)
    at org.testng.xml.TestNGContentHandler.startElement(TestNGContentHandler.java:516)
    at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:506)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(XMLDocumentFragmentScannerImpl.java:1322)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2715)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:607)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:488)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:835)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:764)
    at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:123)
    at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1210)
    at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:568)
    at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl.parse(SAXParserImpl.java:302)
    at javax.xml.parsers.SAXParser.parse(SAXParser.java:195)
    at org.testng.xml.SuiteXmlParser.parse(SuiteXmlParser.java:17)
    at org.testng.xml.SuiteXmlParser.parse(SuiteXmlParser.java:10)
    at org.testng.xml.Parser.parse(Parser.java:170)
    at org.testng.TestNG.initializeSuitesAndJarFile(TestNG.java:299)
    at org.testng.TestNG.run(TestNG.java:972)
    at org.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:122)
    at org.apache.maven.surefire.testng.TestNGXmlTestSuite.execute(TestNGXmlTestSuite.java:88)
    at org.apache.maven.surefire.testng.TestNGProvider.invoke(TestNGProvider.java:104)

这是我的testng.xml

   <?xml version="1.0" encoding="UTF-8" standalone="no"?><suite allow-return-values="false" configfailurepolicy="skip" data-provider-thread-count="10" group-by-instances="false" junit="false" name="Suite" parallel="false" preserve-order="true" skipfailedinvocationcounts="false" thread-count="5">
<test allow-return-values="false" group-by-instances="false" junit="false" name="Test" preserve-order="true" skipfailedinvocationcounts="false">
    <classes>
    <class name="com.org.Console1">
    </class>

    </classes>
</test> <!-- Test -->

这是我的pom.xml

<plugin>
            <artifactId>maven-failsafe-plugin</artifactId>
            <version>2.8</version>
            <configuration>
                <suiteXmlFiles>
                    <suiteXmlFile>testng.xml</suiteXmlFile>
                </suiteXmlFiles>
            </configuration>


            <executions>
                <execution>
                    <goals>
                        <goal>integration-test</goal>
                        <goal>verify</goal>
                    </goals>

                </execution>
            </executions>
        </plugin>

1 个答案:

答案 0 :(得分:0)

您无需为测试指定套件。 surefire-plugin必须配置为捕获所有java类,默认是查找“* Test.java”,我个人不喜欢这种行为。

POM-片段:

  <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.12.4</version>
                <configuration>
                    <includes>
                        <include>**/*.java</include><!-- dont just run *Test.java-files, which is default for surefire -->
                    </includes>
                </configuration>
            </plugin>

请同时确认您的测试类位于正确的位置:

的src /主/的测试 /com/org/Console1.java

它必须在那里,除非你想配置它(我不推荐)