简体   繁体   中英

How to call test classes from src folder and build using maven

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.

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM