我有一个只包含测试类的项目,这些测试类都从一个抽象基类扩展而来。这些测试在intellij中运行良好,并且在运行mvn clean install时指定了正确的配置文件。无法在测试罐内实例化类
我想要做的就是创建一个试验瓶并运行命令行测试,所以我使用这些命令:
mvn -DoutputDirectory=target -f pom.xml dependency:copy-dependencies
这第一个命令是越来越所有的依赖,并把它们沿在目标文件夹中创建的测试罐旁边。
java -cp .;target/* org.testng.TestNG -testjar target/my-test-jar.jar -xmlpathinjar sanity.xml
我得到这个:
[TestNG] [ERROR]
Cannot instantiate class com.myPackage.MyTestClass
类肯定是有,我可以从里面的IntelliJ运行sanity.xml。
最奇怪的一点是,我可以删除我的项目中的Java文件,然后把这个:
public static void main(String[] args){
args = new String[4]
args[0] = "-testjar"
args[1] = "target/my-test-jar.jar"
args[2] = "-xmlpathinjar"
args[3] = "sanity.xml"
org.testng.TestNG.main(args)
}
内的另一个测试类我的项目,它将设法从罐子里实例MyTestClass文件。
有没有人有任何想法呢?我没有得到任何堆栈跟踪或日志文件,只是简单的事实,它不能实例化类。我希望以前有人遇到过,并知道如何解决它。
干杯, 大卫
[编辑 - 添加POM文件的部分内容]
<profiles>
<profile>
<id>buildOnly</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>jar</goal>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>add-test-source</id>
<phase>generate-test-sources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>src/test/groovy</source>
</sources>
</configuration>
</execution>
<execution>
<id>add-resource</id>
<phase>generate-resources</phase>
<goals>
<goal>add-resource</goal>
</goals>
<configuration>
<resources>
<resource>
<directory>src/test/resources</directory>
<targetPath>resources</targetPath>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>gmaven-plugin</artifactId>
<version>1.4</version>
<extensions>true</extensions>
<configuration>
<source>1.6</source>
<providerSelection>1.8</providerSelection>
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.gmaven.runtime</groupId>
<artifactId>gmaven-runtime-1.8</artifactId>
<version>1.4</version>
</dependency>
</dependencies>
<executions>
<execution>
<goals>
<goal>testCompile</goal>
</goals>
<configuration>
<providerSelection>1.8</providerSelection>
<sources>
<fileset>
<directory>${pom.basedir}/src/test/groovy</directory>
<includes>
<include>**/*.groovy</include>
</includes>
</fileset>
</sources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>integrationTest</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>jar</goal>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>add-test-source</id>
<phase>generate-test-sources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>src/test/groovy</source>
</sources>
</configuration>
</execution>
<execution>
<id>add-resource</id>
<phase>generate-resources</phase>
<goals>
<goal>add-resource</goal>
</goals>
<configuration>
<resources>
<resource>
<directory>src/test/resources</directory>
<targetPath>resources</targetPath>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>gmaven-plugin</artifactId>
<version>1.4</version>
<extensions>true</extensions>
<configuration>
<source>1.6</source>
<providerSelection>1.8</providerSelection>
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.gmaven.runtime</groupId>
<artifactId>gmaven-runtime-1.8</artifactId>
<version>1.4</version>
</dependency>
</dependencies>
<executions>
<execution>
<goals>
<goal>testCompile</goal>
</goals>
<configuration>
<providerSelection>1.8</providerSelection>
<sources>
<fileset>
<directory>${pom.basedir}/src/test/groovy</directory>
<includes>
<include>**/*.groovy</include>
</includes>
</fileset>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.10</version>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
<suiteXmlFiles>
<suiteXmlFile>${testng.xml.file}</suiteXmlFile>
</suiteXmlFiles>
<properties>
<property>
<name>usedefaultlisteners</name>
<value>false</value>
</property>
<property>
<name>listener</name>
<value>org.testng.reporters.TestHTMLReporter,org.testng.reporters.JUnitXMLReporter,org.testng.reporters.SuiteHTMLReporter,org.testng.reporters.FailedReporter,org.testng.reporters.EmailableReporter,org.testng.reporters.JUnitReportReporter</value>
</property>
</properties>
<systemProperties>
<property>
<name>isCI</name>
<value>${isCI}</value>
</property>
<property>
<name>browser</name>
<value>${browser}</value>
</property>
<property>
<name>remote</name>
<value>${remote}</value>
</property>
<property>
<name>port</name>
<value>${port}</value>
</property>
<property>
<name>environment</name>
<value>${environment}</value>
</property>
<property>
<name>subDomain</name>
<value>${subDomain}</value>
</property>
</systemProperties>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
你可以显示这个POM文件项目? – khmarbaise
不是全部,我可以显示配置文件和插件部分。我将编辑我的文章并将其放入。 – user1147618