繁体   English   中英

如何从 src 文件夹调用测试类并使用 maven 构建

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

我正在尝试使用 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 新手,请任何人帮我找出问题。

src/main/java的类永远不应该调用src/test/java src/test/java中的类用于测试src/main/java 它们不打算用作依赖项或自建测试框架的一部分。

如果要构建用于测试的 jar,请将类放入src/main/java

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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