Reputation: 539
I am trying to call test classes from src main using maven but unable compile using maven my project structure is like below
My main class looks like
package 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();
}
}
My test class looks like
package com.automation.selenium.test.demo;
public class TestClass {
public void testMethod() {
System.out.println("!!!!!!!!!!!!!!! Calling From Test Class !!!!!!!!!!!!");
}
}
My pom.xml is
<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>
I have use the following command to run
clean compiler:testCompile exec:java
but it is showing the following error
[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
I am new in Maven anyone please help me to findout the issue.
Upvotes: 2
Views: 4127
Reputation: 35903
A class in src/main/java
should never call a class in src/test/java
. Classes in src/test/java
are meant to test the classes in src/main/java
. They are not meant to be used as dependencies or parts of self-constructed test frameworks.
If you want to build a jar for testing, put the classes into src/main/java
.
Upvotes: 3