maven - mvn 测试不起作用。它只显示 'BUILD SUCCESS'

标签 maven

我陷入了这个问题。我正在尝试用 maven 测试这个项目。我输入了“mvn test”、“mvn test-compile”、“mvn package”等等。但它总是显示像这样的相同输出:

[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building WorkflowProject Maven 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.177s
[INFO] Finished at: Sun Sep 29 11:10:25 KST 2013
[INFO] Final Memory: 6M/235M
[INFO] ------------------------------------------------------------------------

整个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/maven-v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion>
<groupId>workflow.ss13</groupId>
<artifactId>WorkflowProject</artifactId>
<version>1.0-SNAPSHOT</version>
<name>WorkflowProject Maven</name>
<url>http://maven.apache.org</url>
<packaging>pom</packaging>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>

<repositories>
    <repository>
        <id>prime-repo</id>
        <name>PrimeFaces Maven Repository</name>
        <url>http://repository.primefaces.org</url>
        <layout>default</layout>
    </repository>
    <repository>
        <id>HibernateJBoss</id>
        <name>JBoss Community Repo</name>
        <url>https://repository.jboss.org/nexus/content/groups/public/</url>
    </repository>
    <repository>
        <id>maven</id>
        <name>Java Maven</name>
        <url>http://download.java.net/maven/2</url>
    </repository>
    <repository>
        <id>Activiti</id>
        <url>http://maven.alfresco.com/nexus/content/repositories/activiti</url>
    </repository>
</repositories>

<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.10</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.primefaces</groupId>
        <artifactId>primefaces</artifactId>
        <version>3.4.2</version>
    </dependency>
    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpclient</artifactId>
        <version>4.0-alpha2</version>
    </dependency>
    <dependency>
        <groupId>com.sun.faces</groupId>
        <artifactId>jsf-api</artifactId>
        <version>2.0.3</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>com.sun.faces</groupId>
        <artifactId>jsf-impl</artifactId>
        <version>2.0.3</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
        <version>1.2</version>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>3.0.1</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf</artifactId>
        <version>2.7.0</version>
        <type>pom</type>
    </dependency>
    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-frontend-jaxws</artifactId>
        <version>2.7.0</version>
    </dependency>
    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-transports-http</artifactId>
        <version>2.7.0</version>
    </dependency>
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.21</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-search</artifactId>
        <version>4.1.1.Final</version>
    </dependency>
    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-ws-security</artifactId>
        <version>2.7.0</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>3.1.2.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>3.1.2.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>com.google.guava</groupId>
        <artifactId>guava</artifactId>
        <version>13.0.1</version>
    </dependency>
    <dependency>
        <groupId>org.json</groupId>
        <artifactId>json</artifactId>
        <version>20090211</version>
    </dependency>
    <dependency>
        <groupId>com.restfb</groupId>
        <artifactId>restfb</artifactId>
        <version>1.6.11</version>
    </dependency>
    <dependency>
        <groupId>ch.qos.logback</groupId>
        <artifactId>logback-classic</artifactId>
        <version>1.0.7</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.6.6</version>
    </dependency>
    <dependency>
        <groupId>javax.mail</groupId>
        <artifactId>mail</artifactId>
        <version>1.4</version>
    </dependency>
    <dependency>
        <groupId>javax.activation</groupId>
        <artifactId>activation</artifactId>
        <version>1.1-rev-1</version>
    </dependency>
    <dependency>
        <groupId>commons-io</groupId>
        <artifactId>commons-io</artifactId>
        <version>1.3.2</version>
    </dependency>
    <dependency>
        <groupId>commons-fileupload</groupId>
        <artifactId>commons-fileupload</artifactId>
        <version>1.2.1</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-test</artifactId>
        <version>3.1.2.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-tx</artifactId>
        <version>3.1.2.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>cglib</groupId>
        <artifactId>cglib</artifactId>
        <version>2.2.2</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-orm</artifactId>
        <version>3.1.2.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>javax.inject</groupId>
        <artifactId>javax.inject</artifactId>
        <version>1</version>
    </dependency>
    <dependency>
        <groupId>org.apache.tomcat</groupId>
        <artifactId>tomcat-el-api</artifactId>
        <version>7.0.34</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>3.1.2.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>joda-time</groupId>
        <artifactId>joda-time</artifactId>
        <version>2.1</version>
    </dependency>
    <dependency>
        <groupId>org.activiti</groupId>
        <artifactId>activiti-engine</artifactId>
        <version>5.12</version>
    </dependency>
    <dependency>
        <groupId>org.activiti</groupId>
        <artifactId>activiti-spring</artifactId>
        <version>5.12</version>
    </dependency>
    <dependency>
        <groupId>com.h2database</groupId>
        <artifactId>h2</artifactId>
        <version>1.3.168</version>
    </dependency>
</dependencies>
<build>
    <finalName>WorkflowProject</finalName>
    <pluginManagement>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.5.1</version>
                <configuration>
                    <source>6</source>
                    <target>6</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-site-plugin</artifactId>
                <version>3.2</version>
                <configuration>
                    <reportPlugins>
                        <plugin>
                            <groupId>org.codehaus.mojo</groupId>
                            <artifactId>cobertura-maven-plugin</artifactId>
                            <version>2.5.2</version>
                        </plugin>
                        <plugin>
                            <groupId>org.apache.maven.plugins</groupId>
                            <artifactId>maven-project-info-reports-plugin</artifactId>
                            <version>2.6</version>
                            <configuration>
                                <dependencyLocationsEnabled>false</dependencyLocationsEnabled>
                            </configuration>
                        </plugin>
                        <plugin>
                            <groupId>org.apache.maven.plugins</groupId>
                            <artifactId>maven-surefire-report-plugin</artifactId>
                            <version>2.4.3</version>
                        </plugin>
                        <plugin>
                            <groupId>org.apache.maven.plugins</groupId>
                            <artifactId>maven-checkstyle-plugin</artifactId>
                            <version>2.9.1</version>
                            <configuration>
                                <configLocation>config/sun_checks.xml</configLocation>
                            </configuration>
                        </plugin>
                        <plugin>
                            <groupId>org.apache.maven.plugins</groupId>
                            <artifactId>maven-javadoc-plugin</artifactId>
                            <version>2.9</version>
                        </plugin>
                    </reportPlugins>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.tomcat.maven</groupId>
                <artifactId>tomcat7-maven-plugin</artifactId>
                <version>2.0</version>
                <configuration>
                    <url>http://localhost:8080/manager</url>
                    <path>/WorkflowProject</path>
                    <username>tomcat</username>
                    <password>tomcat</password>
                </configuration>
            </plugin>               
        </plugins>
    </pluginManagement>
</build>
<issueManagement>
    <system>Redmine</system>
    <url>https://sat.inso.tuwien.ac.at/redmine/projects/qse-ase-ws12-03/issues</url>
</issueManagement>
</project>

最佳答案

测试可由 Surefire Maven plugin 执行及其test goal .

Maven有多个连续的lifecycle phases .其中之一是 test 阶段,这将是执行测试的好阶段。

现在,需要将目标和阶段绑定(bind)在一起。你可以自己绑定(bind)它们,使用执行:

<plugin>
    <artifactId>maven-surefire-plugin</artifactId>
    <executions>
        <id>...</id>
        <goals>
            <goal>test</goal>
        </goals>
        <phase>test</phase>
       ...
    </executions>
</plugin>

还有default (built-in) lifecycle mappings为了共同的目标。根据项目类型(打包)不同default mappings适用。

打包 jar 会将 surefire:test 绑定(bind)到 test 阶段。包装 pom 不会,这就是您的特定期望没有得到满足的原因。

您的选择是:

  • 为 Surefire 插件添加执行
  • 将您的项目转换为另一种包装类型

如果您的项目有 Java 代码(引用 maven-compiler-plugin 建议),将其转换为 packaging jar可能是合适的。如果您确定这不应该是一个 jar 项目,那么定义您想要的 execution 并没有错。如果你想走得很花哨,你可以introduce your own packaging type及其后续的生命周期映射。

关于maven - mvn 测试不起作用。它只显示 'BUILD SUCCESS',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19073754/

相关文章:

maven - dropwizard 的不同组 ID(io.dropwizard 和 com.yammer.dropwizard)

maven - 使用sonar运行maven项目时忽略测试用例

java - 异常设计与应用需求不匹配

linux - 在 bash 脚本 (Linux) 中从 maven POM 读取属性

maven - 父 pom 是在其子代的相同 groupid 下还是在其自己/父代下创建的?

maven - 有没有办法过滤Maven的依赖:tree by scope?

java - java中pom.xml文件有什么用?

java - eclipse maven 循环占位符引用错误使用配置文件

java - GraalVM - 在类路径上找不到语言和多语言实现

java - 嵌入式 ActiveMQ 代理需要哪些依赖项?