无法在错误的项目上执行目标

问题描述 投票:0回答:2

我尝试运行一个继续失败的单元测试。最大的问题 - 或者我只是不明白这是怎么可能的 - 是当我尝试运行测试时,我看到它试图运行错误的项目。

当我运行时:

mvn test -Dtest=com.alphad.cdees.backend.test.logic.BuyLogicTest

我收到此错误:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.22.1:test (default-test) on project cdees-core: No tests were executed! (Set -DfailIfNoTests=false to ignore this error.) -> [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/MojoFailureException [ERROR] [ERROR] After correcting the problems, you can resume the build with the command [ERROR] mvn <goals> -rf :cdees-core

我不明白为什么它试图在cdees-core项目上运行这个测试而不是cdees-backend项目 - 我有单元测试类BuyLogicTest。

这是项目的配置:'

<?xml version="1.0" encoding="UTF-8"?>
<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">
    <parent>
        <artifactId>cdees-parent</artifactId>
        <groupId>com.alphad.cdees</groupId>
        <version>3.14.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>cdees-backend</artifactId>
    <packaging>jar</packaging>

    <properties>
        <main.basedir>${project.parent.basedir}</main.basedir>
        <postgres.jdbc.version>42.2.5</postgres.jdbc.version>
        <cdees.postgres.ipAddress>${docker.container.postgres-mysoftware-backend-test.ip}</cdees.postgres.ipAddress>
        <docker.disable>${skipTests}</docker.disable>
        <!-- Containers name identified globally by their alias set in the build configuration -->
        <docker.containerNamePattern>%a</docker.containerNamePattern>
    </properties>

    <build>
        <testResources>
            <testResource>
                <directory>src/test/java</directory>
                <excludes>
                    <exclude>**/*.java</exclude>
                </excludes>
            </testResource>
            <testResource>
                <directory>src/test/resources</directory>
            </testResource>
        </testResources>
        <resources>
            <resource>
                <directory>src/main/java</directory>
                <excludes>
                    <exclude>**/*.java</exclude>
                </excludes>
            </resource>
            <resource>
                <directory>src/main/resources</directory>
            </resource>
        </resources>
        <plugins>
            <!--
                Enable this plugin for code coverage measurement
                NOTE: the plugin put an additional member ($jaCoCo) in each
                class, making some unit test to fail
            -->
<!--
            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>0.8.0</version>
                <executions>
                    <execution>
                        <id>pre-unit-test</id>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                        <configuration>
                            <propertyName>surefireArgLine</propertyName>
                        </configuration>
                    </execution>
                    <execution>
                        <id>post-unit-test</id>
                        <phase>test</phase>
                        <goals>
                            <goal>report</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
-->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>3.1.1</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>test-jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.22.1</version>
                <configuration>
                    <!-- Propagate project properties to system properties in the forked executor -->
                    <systemPropertyVariables>
                        <cdees.postgres.ipAddress>${cdees.postgres.ipAddress}</cdees.postgres.ipAddress>
                        <cdees.postgres.port>${cdees.postgres.port}</cdees.postgres.port>
                    </systemPropertyVariables>
                </configuration>
            </plugin>
            <plugin>
                <groupId>io.fabric8</groupId>
                <artifactId>docker-maven-plugin</artifactId>
                <!-- See https://dmp.fabric8.io/ -->
                <version>0.27.2</version>
                <configuration>
                    <!-- change here if you are using another port/host, e.g. 4243 -->
                    <dockerHost>tcp://localhost:2375</dockerHost>
                    <skip>${docker.disable}</skip>
                    <!-- Enable this for debugging docker image/container evolution -->
                    <verbose>false</verbose>
                    <images>
                        <image>
                            <name>postgres:mysoftware-backend-test</name>
                            <alias>postgres-mysoftware-backend-test</alias>
                            <build>
                                <nocache>true</nocache>
                                <dockerFileDir>postgres</dockerFileDir>
                                <assembly>
                                    <!-- The assembly name is referenced in the Dockerfile -->
                                    <name>db-files</name>
                                    <inline>
                                        <!-- These files cannot be accessed by the image builder, we need
                                             for them to create a special maven-assembly accessor -->
                                        <files>
                                            <file><source>../db/GeoIPCountryWhois.csv</source></file>
                                            <file><source>../db/schema.sql</source></file>
                                        </files>
                                    </inline>
                                </assembly>
                            </build>
                            <run>
                                <wait>
                                    <time>60000</time>
                                    <tcp>
                                        <host>${cdees.postgres.ipAddress}</host>
                                        <ports>
                                            <port>${cdees.postgres.port}</port>
                                        </ports>
                                    </tcp>
                                    <!-- This is a real test, server side, stating that the server is ready -->
                                    <exec>
                                        <breakOnError>true</breakOnError>
                                        <postStart>
                                            wait_for_pg_server.sh
                                        </postStart>
                                    </exec>
                                </wait>
                            </run>
                        </image>
                    </images>
                </configuration>
                <executions>
                    <execution>
                        <id>default-cli</id>
                        <goals>
                            <goal>help</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>docker-build-img-start-cnt</id>
                        <phase>test-compile</phase>
                        <goals>
                            <goal>stop</goal>
                            <goal>build</goal>
                            <goal>start</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>docker-stop-cnt-rm-img</id>
                        <phase>test</phase>
                        <goals>
                            <goal>stop</goal>
                            <goal>remove</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>docker-rm-img</id>
                        <phase>clean</phase>
                        <goals>
                            <goal>stop</goal>
                            <goal>remove</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>sql-maven-plugin</artifactId>
                <version>1.5</version>

                <dependencies>
                    <!-- specify the dependent jdbc driver here -->
                    <dependency>
                        <groupId>org.postgresql</groupId>
                        <artifactId>postgresql</artifactId>
                        <version>${postgres.jdbc.version}</version>
                    </dependency>
                </dependencies>

                <!-- common configuration shared by all executions -->
                <configuration>
                    <skip>${skipTests}</skip>
                    <driver>org.postgresql.Driver</driver>
                    <url>jdbc:postgresql://${cdees.postgres.ipAddress}:${cdees.postgres.port}/silentdefense</url>
                    <username>user</username>
                    <password>pass</password>
                    <!-- You can comment out username/password configurations and
                         have maven to look them up in your settings.xml using ${settingsKey}
                    -->
                    <delimiterType>row</delimiterType>
                    <autocommit>true</autocommit>
                </configuration>

                <executions>
                    <execution>
                        <id>create-data</id>
                        <phase>test-compile</phase>
                        <goals>
                            <goal>execute</goal>
                        </goals>
                        <configuration>
                            <orderFile>ascending</orderFile>
                            <fileset>
                                <basedir>${project.basedir}</basedir>
                                <includes>
                                    <include>src/test/resources/UnitTestDBData.sql</include>
                                </includes>
                            </fileset>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <!-- Our own libraries -->
        <dependency>
            <groupId>com.alphad.cdees</groupId>
            <artifactId>cdees-core</artifactId>
            <version>${project.parent.version}</version>
        </dependency>
        <dependency>
            <groupId>com.alphad.cdees</groupId>
            <artifactId>cdees-core</artifactId>
            <type>test-jar</type>
            <version>${project.parent.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.alphad.cdees</groupId>
            <artifactId>cdees-driver-scp</artifactId>
            <version>${project.parent.version}</version>
        </dependency>
        <dependency>
            <groupId>com.alphad.cdees</groupId>
            <artifactId>cdees-driver-scp</artifactId>
            <type>test-jar</type>
            <version>${project.parent.version}</version>
            <scope>test</scope>
        </dependency>

        <!-- Third party libraries -->
        <dependency>
            <groupId>org.freemarker</groupId>
            <artifactId>freemarker</artifactId>
            <version>2.3.28</version>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-digester3</artifactId>
            <version>3.2</version>
        </dependency>
        <dependency>
            <groupId>org.jasypt</groupId>
            <artifactId>jasypt</artifactId>
            <version>1.9.2</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>${org.slf4j.version}</version>
        </dependency>
        <dependency>
            <groupId>org.quartz-scheduler</groupId>
            <artifactId>quartz</artifactId>
            <version>1.8.6</version>
        </dependency>
        <dependency>
            <groupId>org.hyperic</groupId>
            <artifactId>sigar</artifactId>
            <version>1.7-SVN</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.jrobin</groupId>
            <artifactId>jrobin</artifactId>
            <version>1.5.9</version>
        </dependency>
        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <version>${postgres.jdbc.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>io.druid</groupId>
            <artifactId>druid-processing</artifactId>
            <version>0.8.1</version>
            <exclusions>
                <exclusion>
                    <artifactId>log4j-slf4j-impl</artifactId>
                    <groupId>org.apache.logging.log4j</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>log4j-api</artifactId>
                    <groupId>org.apache.logging.log4j</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>log4j-core</artifactId>
                    <groupId>org.apache.logging.log4j</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>log4j-jul</artifactId>
                    <groupId>org.apache.logging.log4j</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>log4j-1.2-api</artifactId>
                    <groupId>org.apache.logging.log4j</groupId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.apache.kafka</groupId>
            <artifactId>kafka_2.10</artifactId>
            <version>0.8.2.1</version>
            <exclusions>
                <exclusion>
                    <groupId>log4j</groupId>
                    <artifactId>log4j</artifactId>
                </exclusion>
                <!--
                This dependency exclusion was removed in 3.13.0 to support the KafkaForwarderService
                <exclusion>
                    <groupId>org.apache.zookeeper</groupId>
                    <artifactId>zookeeper</artifactId>
                </exclusion>
                -->
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>slf4j-api</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>net.jpountz.lz4</groupId>
                    <artifactId>lz4</artifactId>
                </exclusion>
                <!--
                This dependency exclusion was removed in 3.13.0 to support the KafkaForwarderService
                <exclusion>
                    <groupId>com.101tec</groupId>
                    <artifactId>zkclient</artifactId>
                </exclusion>
                -->
                <exclusion>
                    <groupId>net.sf.jopt-simple</groupId>
                    <artifactId>jopt-simple</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>com.icegreen</groupId>
            <artifactId>greenmail</artifactId>
            <version>1.5.9</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.docx4j</groupId>
            <artifactId>docx4j</artifactId>
            <version>3.3.7</version>
        </dependency>
        <dependency>
            <groupId>com.googlecode.protobuf-java-format</groupId>
            <artifactId>protobuf-java-format</artifactId>
            <version>1.4</version>
        </dependency>
        <dependency>
            <groupId>com.unboundid</groupId>
            <artifactId>unboundid-ldapsdk</artifactId>
            <version>${unboundid-ldapsdk.version}</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
</project>

'

已解决我试图在错误的目录中运行它。

java maven unit-testing
2个回答
1
投票

试试这个:

  1. 清理您的项目
  2. 建立干净
  3. 运行mvn test -Dtest = com.alphad.cdees.backend.test.logic.BuyLogicTest test
  4. 如果不起作用,请尝试mvn test -Dtest = BuyLogicTest测试

0
投票

如果你的后端依赖于核心,它将首先运行核心库的验证,编译,测试和jar任务的过程,以便它可以在后端使用。 Maven Build Lifecycle

© www.soinside.com 2019 - 2024. All rights reserved.