伙计们,我知道我在问一个非常愚蠢的问题,但是我很好奇为什么我的测试没有运行。

我已经创建了一个简单的Maven项目(没有Junits等,只是一个简单的主类),在测试文件夹中只有一个主类,而我试图通过pom.xml执行相同的项目。

我已经解决了现有问题,但是并没有解决它

当我尝试执行它时,得到以下输出。

Running samplemav.TestOne
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.015 sec


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>samplemav</groupId>
<artifactId>samplemav</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.20</version>
            <configuration>
                <includes>
                    <include>samplemav.TestOne</include>
                </includes>
            </configuration>
        </plugin>
    </plugins>
</build>




Java类

 package samplemav;
 public class TestOne {

    public static void main(String args[]){

        System.out.println("test");
    }

}


问候

最佳答案

您可能要使用Junit进行单元测试。

package samplemav;
import org.junit.Test;
 public class TestOne {

    @Test
    public void test() {

        System.out.println("test");
    }

}


并添加您的pom.xml测试依赖项

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

10-07 13:24
查看更多