java - Maven 未运行测试

标签 java eclipse apache maven selenium

我在 Eclipse 中创建了一个新的 Maven 项目,通过使用 HtmlUnitDriver 和 FirefoxDriver 来运行简单的测试来拉出网页并检查页面上的标题。当我运行 Maven 命令 mvn test 时,这就是我得到的全部内容:

[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building my-app 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ my-app ---
[WARNING] Using platform encoding (MacRoman actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /Users/Andrew/Development/code/my-app/src/main/resources
[INFO] 
[INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) @ my-app ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ my-app ---
[WARNING] Using platform encoding (MacRoman actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /Users/Andrew/Development/code/my-app/src/test/resources
[INFO] 
[INFO] --- maven-compiler-plugin:2.5.1:testCompile (default-testCompile) @ my-app ---
[WARNING] File encoding has not been set, using platform encoding MacRoman, i.e. build is platform dependent!
[INFO] Compiling 1 source file to /Users/Andrew/Development/code/my-app/target/test-classes
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ my-app ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.049s
[INFO] Finished at: Fri Jan 31 11:53:38 EST 2014
[INFO] Final Memory: 12M/81M
[INFO] ------------------------------------------------------------------------

当我在 Eclipse 中运行相同的 Maven 命令时,它显示以下内容:

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building my-app 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.5:resources (default-resources) @ my-app ---
[debug] execute contextualize
[WARNING] Using platform encoding (MacRoman actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /Users/Andrew/Development/code/my-app/src/main/resources
[INFO] 
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ my-app ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:2.5:testResources (default-testResources) @ my-app ---
[debug] execute contextualize
[WARNING] Using platform encoding (MacRoman actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /Users/Andrew/Development/code/my-app/src/test/resources
[INFO] 
[INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ my-app ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-surefire-plugin:2.10:test (default-test) @ my-app ---
[INFO] Surefire report directory: /Users/Andrew/Development/code/my-app/target/surefire-reports

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

Results :

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

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.878s
[INFO] Finished at: Fri Jan 31 11:58:23 EST 2014
[INFO] Final Memory: 5M/81M
[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>com.mycompany.app</groupId>
  <artifactId>my-app</artifactId>
  <packaging>jar</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>my-app</name>
  <url>http://maven.apache.org</url>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.seleniumhq.selenium</groupId>
      <artifactId>selenium-java</artifactId>
      <version>2.39.0</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.7.5</version>
    </dependency>
    <dependency>
        <groupId>org.apache.maven.surefire</groupId>
        <artifactId>surefire</artifactId>
        <version>2.16</version>
        <type>pom</type>
     </dependency> 
  </dependencies>
</project>

最佳答案

您的意思是添加 org.apache.maven.surefire作为 <dependencies> 下的 POM 依赖项?

Surefire 插件的大多数用法都是在 <pluginManagement> 下配置的部分:

<build>
  <pluginManagement>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.16</version>
      </plugin>
    </plugins>
  </pluginManagement>
</build>

关于java - Maven 未运行测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21485744/

相关文章:

java - Apache POI : Getting wrong number/string values reading from xlsx while xls is workfing fine

设置 root 的 JavaFx FXML 加载文件问题

java表达式从图像数据中删除dat/image部分

由于 Eclipse IDE 导致的 Java 通用问题

linux - Eclipse 中的字体

php - 结合 servlet 和 "normal"网络服务器

java - 使用 Java 泛型确保接收到的参数与类或其子类型相同

java - 无法解决 Maven 中的 httpComponent 依赖关系

Javamail 和 gmail,获取 "PKIX path building failed"

java - 如何初始化 org.apache.commons.math3.geometry.Vector?