1

运行时mvn clean install,一旦我们到达测试部分,我看到

-------------------------------------------------------
 T E S T S
-------------------------------------------------------

Results :

Tests run: 0, Failures: 0, Errors: 0, Skipped: 0

我的surefire插件配置如下:

        <plugin>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
                <testFailureIgnore>false</testFailureIgnore>
                <includes>
                    <include>**/*Test*.java</include>
                </includes>
            </configuration>
        </plugin>

测试文件名遵循这种格式。例如A.javaATest.java它的测试

从中mvn clean install运行的目录结构是标准的

├── src
│   ├── main
│   │   ├── java
│   │   │   └── ***
│   └── test
│       └── java
│           └── ***

个别测试用@Test和注释

import org.junit.Test; 

更多测试名称遵循以下约定

public void testSomething() throws Exception

本着完整的精神,下面是我的pom

<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
         xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <modelVersion>4.0.0</modelVersion>
    <groupId>a.b.c</groupId>
    <artifactId>My_Project</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <packaging>war</packaging>
    <repositories>
        <repository>
            <id>JBOSS_NEXUS</id>
            <url>http://repository.jboss.org/nexus/content/groups/public</url>
        </repository>
    </repositories>
    <build>
        <finalName>My_Project</finalName>
        <plugins>
            <plugin>
                <groupId>com.google.appengine</groupId>
                <artifactId>appengine-maven-plugin</artifactId>
                <version>1.7.4</version>
            </plugin>
            <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.1.1</version>
                <extensions>false</extensions>
                <configuration>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-surefire-plugin</artifactId>
                <vesion></vesion>
                <configuration>
                    <testFailureIgnore>false</testFailureIgnore>
                    <includes>
                        <include>**/*Test*.java</include>
                    </includes>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>cobertura-maven-plugin</artifactId>
                <version>2.5.1</version>
                <configuration>
                    <formats>
                        <format>xml</format>
                        <format>html</format>
                    </formats>
                    <check/>
                </configuration>
                <executions>
                    <execution>
                        <phase>clean</phase>
                        <goals>
                            <goal>cobertura</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
    <reporting>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>cobertura-maven-plugin</artifactId>
                <version>2.5.1</version>
            </plugin>
        </plugins>
    </reporting>
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.8.2</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            ...
        </dependency>
    </dependencies>
</project>

请问我错过了什么?

4

1 回答 1

0

如果信息如此分散,就很难提供帮助。您可能不能或不想透露更多信息,因此我们必须处理我们所看到的。

与我通常的代码的 一个区别<scope>test

    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.8.2</version>
        <scope>test</scope>
    </dependency>

此外,每个测试方法都需要用 注释@Test,而不是类。这可能是您的意思,但是这里的语言有点模棱两可。

由于您使用的是测试的默认设置、位置和命名,因此您可以完全删除该maven-surefire-plugin部分。

您可能需要告诉 maven 您要使用 Java 1.6:

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.0.2</version>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
            </configuration>
        </plugin>
于 2013-02-03T18:39:19.133 回答