Как вызвать тестовые классы из папки src и собрать с помощью maven - PullRequest
1 голос
/ 29 апреля 2019

Я пытаюсь вызвать тестовые классы из src main с помощью maven, но не могу скомпилировать с помощью maven. Структура моего проекта выглядит следующим образом:

enter image description here

Мой основной классвыглядит как

пакет 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, пожалуйста, помогите мне, чтобы выяснить проблему.

1 Ответ

1 голос
/ 29 апреля 2019

Класс в src/main/java никогда не должен вызывать класс в src/test/java.Классы в src/test/java предназначены для проверки классов в src/main/java.Они не предназначены для использования в качестве зависимостей или частей самостоятельно построенных тестовых сред.

Если вы хотите собрать банку для тестирования, поместите классы в src/main/java.

...