简体   繁体   中英

Failed to execute goal on wrong project

I try to run a unit test which continue to fail. The big issue - or maybe I just don't understand how that is possible - is that when I try to run the test I saw it try to run on a wrong project.

When I run that:

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

I get this error:

[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

I don't understand why it try to run this test on cdees-core project and not on cdees-backend project - where I have the unit test class BuyLogicTest .

This is the configuration of the project: '

<?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>

'

SOLVED I tried to run it in the wrong directory.

Try this:

  1. Clean your project
  2. Build clean
  3. run mvn test -Dtest=com.alphad.cdees.backend.test.logic.BuyLogicTest test
  4. if does not work, try mvn test -Dtest=BuyLogicTest test

If your backend depends on the core, it will run through the process of validating, compile, testing and jar task of the core library first so that it can be used in the backend. Maven Build Lifecycle

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