将testNG作为可执行jar文件

时间:2017-09-29 11:52:40

标签: java junit jar testng pom.xml

我编写了一个Java类来运行JUnit Test,它看起来像:

public class test_runner {
   public static void main(String[] args) {
      TestNG test = new TestNG();
      TestListenerAdapter tla = new TestListenerAdapter();
      test.setTestClasses(new Class[] { Test.class });
      test.addListener(tla);
      test.run();
   }
}

当我在工作区内运行时,一切都很好,我的Test.class中的测试将会运行。但是当我将test_runner.class导出为可执行jar文件并使用java -jar test_runner.jar running运行时,测试用例失败,因为属性文件的路径为null。有人能告诉我问题是什么吗? 我的pom.xml如下所示。也许一个插件丢失了?

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.fja.cor.test</groupId>
    <artifactId>jaguar-test-verka</artifactId>
    <version>2.0.1</version>
    <properties>
        <resultoutputdirectory>X:/Testmanagement/Jaguar/jaguar-logs/${maven.build.timestamp}</resultoutputdirectory>
        <testSuite>src/test/resources/testsuites/VerkaSuite1.xml</testSuite>
    </properties>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.15</version>
                <configuration>
                    <systemPropertyVariables>
                        <!--<url>${url}</url>
                        <errPath>${errPath}</errPath>
                        <webdriver.firefox.bin>C:\Program Files (x86)\Mozilla Firefox\firefox</webdriver.firefox.bin>
                        <webdriver.ie.driver>D:/jaguar/IEDriverServer.exe</webdriver.ie.driver>
                        <FAGT_VTRNR>${FAGT_VTRNR}</FAGT_VTRNR>-->
                    </systemPropertyVariables>
                    <suiteXmlFiles>
                        <suiteXmlFile>${testSuite}</suiteXmlFile>
                    </suiteXmlFiles>
                    <properties>
                        <property>
                            <name>listener</name>
                            <value>com.cor.fja.jaguar.architecture.listener.JaguarErrListener</value>
                        </property>
                    </properties>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <dependencies>
        <dependency>
            <groupId>javax.mail</groupId>
            <artifactId>mail</artifactId>
            <version>1.4.7</version>
        </dependency>
        <dependency>
            <groupId>org.jboss.arquillian.graphene</groupId>
            <artifactId>graphene-webdriver</artifactId>
            <type>pom</type>
            <version>2.1.0.CR2</version>
        </dependency>
        <dependency>
            <groupId>org.jboss.arquillian.testng</groupId>
            <artifactId>arquillian-testng-standalone</artifactId>
            <version>1.1.11.Final</version>
        </dependency>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi</artifactId>
            <version>3.9</version>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>2.53.0</version>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-api</artifactId>
            <version>2.53.0</version>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-common</artifactId>
            <version>2.0b1</version>
        </dependency>
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>6.8.7</version>
        </dependency>
        <dependency>
            <groupId>com.thoughtworks.xstream</groupId>
            <artifactId>xstream</artifactId>
            <version>1.4.4</version>
            <type>jar</type>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>xml-apis</groupId>
            <artifactId>xml-apis</artifactId>
            <version>1.4.01</version>
        </dependency>
        <dependency>
            <groupId>org.jdom</groupId>
            <artifactId>jdom2</artifactId>
            <version>2.0.5</version>
        </dependency>
        <dependency>
            <groupId>org.easytesting</groupId>
            <artifactId>fest-swing</artifactId>
            <version>1.2.1</version>
        </dependency>
        <dependency>
            <groupId>org.easytesting</groupId>
            <artifactId>fest-swing-testng</artifactId>
            <version>1.2.1</version>
        </dependency>
        <dependency>
            <groupId>xmlunit</groupId>
            <artifactId>xmlunit</artifactId>
            <version>1.5</version>
        </dependency>
        <dependency>
            <groupId>org.apache.pdfbox</groupId>
            <artifactId>pdfbox</artifactId>
            <version>1.8.6</version>
        </dependency>
        <dependency>
            <groupId>org.dbunit</groupId>
            <artifactId>dbunit</artifactId>
            <version>2.5.0</version>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.6</version>
            <type>jar</type>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>com.fja.cor.jaguar</groupId>
            <artifactId>jaguar-common</artifactId>
            <version>2.0.5</version>
        </dependency>
    </dependencies>
    <reporting>
        <outputDirectory>${resultoutputdirectory}/TestResult-${maven.build.timestamp}</outputDirectory>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-report-plugin</artifactId>
                <version>2.12.4</version>
                <configuration>
                    <outputName>TestResult</outputName>
                    <outputDirectory>${resultoutputdirectory}/TestResult-${maven.build.timestamp}</outputDirectory>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-site-plugin</artifactId>
                <version>3.0</version>
                <configuration>
                    <outputDirectory>${resultoutputdirectory}/TestResult-${maven.build.timestamp}</outputDirectory>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-project-info-reports-plugin</artifactId>
                <version>2.5.1</version>
                <reportSets>
                    <reportSet>
                        <reports>
                        </reports>
                    </reportSet>
                </reportSets>
            </plugin>
        </plugins>
    </reporting>
</project>

0 个答案:

没有答案