我正在尝试使用maven从src main调用测试类,但是无法使用maven进行编译,我的项目结构如下所示
我的主班看起来像
包com.automation.selenium.demo;
import com.automation.selenium.test.demo.TestClass;
public class EntryClass {
public static void main(String[] args) {
System.out.println("!!!!!!!!!!!!!!! Calling From Main Class !!!!!!!!!!!!");
TestClass testNGtest = new TestClass();
testNGtest.testMethod();
}
}
我的测试班级
package com.automation.selenium.test.demo;
public class TestClass {
public void testMethod() {
System.out.println("!!!!!!!!!!!!!!! Calling From Test Class !!!!!!!!!!!!");
}
}
我的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.ibm.automation.selenium.demo</groupId>
<artifactId>Demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.testng/testng -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.14.3</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<configuration>
<executable>java</executable>
<arguments>
<argument>-classpath</argument>
<classpath/>
<argument>${project.build.directory}\test-classes\com\automation\selenium\test\demo</argument>
</arguments>
<!-- <testSourceRoot>${project.basedir}/src/test{</testSourceRoot> -->
<mainClass>com.automation.selenium.demo.EntryClass</mainClass>
</configuration>
</plugin>
</plugins>
</build>
</project>
我已经使用以下命令运行
clean compiler:testCompile exec:java
但显示以下错误
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.6.0:java (default-cli) on project Demo: Unable to parse configuration of mojo org.codehaus.mojo:exec-maven-plugin:1.6.0:java for parameter arguments: Cannot store value into array: ArrayStoreException -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginConfigurationException
我是Maven的新手,任何人都可以帮助我找出问题所在。
答案 0 :(得分:1)
src/main/java
中的类永远不要调用src/test/java
中的类。 src/test/java
中的类旨在测试src/main/java
中的类。它们无意用作自建测试框架的依赖项或组成部分。
如果要构建一个jar进行测试,请将这些类放入src/main/java
。