Maven的不运行测试

Maven的不运行测试

本文介绍了Maven的不运行测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建Eclipse的一个新的Maven项目运行同时使用HtmlUnitDriver和FirefoxDriver拉上了一个网页,并检查页面标题简单的测试。当我运行Maven的命令MVN测试这是所有我得到的:

  [信息]扫描项目...
[信息]
[INFO] ----------------------------------------------- -------------------------
[INFO]我号楼应用1.0快照
[INFO] ----------------------------------------------- -------------------------
[信息]
[信息] --- Maven的资源 - 插件:2.6:资源(缺省资源)@我的应用---
【警告】使用平台编码(实际上的MacRoman)复制过滤资源,即构建依赖于平台!
[信息]跳到不存在的resourceDirectory /用户/安德鲁/开发/ code /我的应用/ src目录/主/资源
[信息]
[信息] --- Maven的编译器插件:2.5.1:编译(默认编译)@我的应用---
[INFO]没有可编译 - 所有的类都是最新的
[信息]
[信息] --- Maven的资源 - 插件:2.6:testResources(缺省testResources)@我的应用---
【警告】使用平台编码(实际上的MacRoman)复制过滤资源,即构建依赖于平台!
[信息]跳到不存在的resourceDirectory /用户/安德鲁/开发/ code /我的应用/ src目录/测试/资源
[信息]
[信息] --- Maven的编译器插件:2.5.1:testCompile(缺省testCompile)@我的应用---
[警告]文件编码尚未设置,使用平台编码的MacRoman,即构建依赖于平台!
[INFO]将源文件编译到/用户/安德鲁/开发/ code /我的应用/目标/测试类
[信息]
[信息] --- Maven的万无一失-插件:2.12.4:测试(默认测试)@我的应用---
[INFO] ----------------------------------------------- -------------------------
[INFO] BUILD成功
[INFO] ----------------------------------------------- -------------------------
[INFO]总时间:3.049s
[INFO]在表面处理:星期五1月31日11点53分38秒美国东部时间2014年
[INFO]最后的内存:12M / 81M
[INFO] ----------------------------------------------- -------------------------

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

  SLF4J:无法加载类org.slf4j.impl.StaticLoggerBinder。
SLF4J:默认到无操作(NOP)记录器的实施
SLF4J:见http://www.slf4j.org/$c$cs.html#StaticLoggerBinder进一步的细节。
[INFO]扫描项目...
[信息]
[INFO] ----------------------------------------------- -------------------------
[INFO]我号楼应用1.0快照
[INFO] ----------------------------------------------- -------------------------
[信息]
[信息] --- Maven的资源 - 插件:2.5:资源(缺省资源)@我的应用---
[调试]执行情境化
【警告】使用平台编码(实际上的MacRoman)复制过滤资源,即构建依赖于平台!
[信息]跳到不存在的resourceDirectory /用户/安德鲁/开发/ code /我的应用/ src目录/主/资源
[信息]
[信息] --- Maven的编译器插件:2.3.2:编译(默认编译)@我的应用---
[INFO]没有可编译 - 所有的类都是最新的
[信息]
[信息] --- Maven的资源 - 插件:2.5:testResources(缺省testResources)@我的应用---
[调试]执行情境化
【警告】使用平台编码(实际上的MacRoman)复制过滤资源,即构建依赖于平台!
[信息]跳到不存在的resourceDirectory /用户/安德鲁/开发/ code /我的应用/ src目录/测试/资源
[信息]
[信息] --- Maven的编译器插件:2.3.2:testCompile(缺省testCompile)@我的应用---
[INFO]没有可编译 - 所有的类都是最新的
[信息]
[信息] --- Maven的万无一失-插件:2.10:测试(默认测试)@我的应用---
[INFO]神火报告目录:/用户/安德鲁/开发/ code /我的应用/目标/万无一失的报表-------------------------------------------------- -----
 T E式T小号
-------------------------------------------------- -----结果:测试运行:0,失败:0,错误:0,跳过:0[INFO] ----------------------------------------------- -------------------------
[INFO] BUILD成功
[INFO] ----------------------------------------------- -------------------------
[INFO]总时间:3.878s
[INFO]在表面处理:星期五1月31日11时58分23秒美国东部时间2014年
[INFO]最后的内存:5M / 81M
[INFO] ----------------------------------------------- -------------------------

这是我的pom.xml的,谁想要检查是否可能是这个问题:

 <项目的xmlns =htt​​p://maven.apache.org/POM/4.0.0的xmlns:XSI =htt​​p://www.w3.org/2001 / XML模式实例
  XSI:的schemaLocation =htt​​p://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd\">
  < modelVersion> 4.0.0< / modelVersion>
  <&的groupId GT; com.mycompany.app< /的groupId>
  < artifactId的>我应用< / artifactId的>
  <包装和GT;&罐子LT; /包装>
  <&版GT; 1.0-SNAPSHOT< /版本>
  <名称>我的应用< /名称>
  &LT; URL&GT; HTTP://maven.apache.org< / URL&GT;
  &LT;依赖和GT;
    &LT;&依赖性GT;
      &LT;&的groupId GT;的JUnit&LT; /的groupId&GT;
      &LT;&的artifactId GT;的JUnit&LT; / artifactId的&GT;
      &LT;&版GT;&4.11 LT; /版本&GT;
      &LT;&范围GT;试验&LT; /&范围GT;
    &LT; /依赖性&GT;
    &LT;&依赖性GT;
      &LT;&的groupId GT; org.seleniumhq.selenium&LT; /的groupId&GT;
      &LT;&的artifactId GT;硒的Java&LT; / artifactId的&GT;
      &LT;&版GT; 2.39.0&LT; /版本&GT;
    &LT; /依赖性&GT;
    &LT;&依赖性GT;
        &LT;&的groupId GT; org.slf4j&LT; /的groupId&GT;
        &LT;&的artifactId GT; SLF4J的API&LT; / artifactId的&GT;
        &LT;&版GT; 1.7.5&LT; /版本&GT;
    &LT; /依赖性&GT;
    &LT;&依赖性GT;
        &LT;&的groupId GT; org.apache.maven.surefire&LT; /的groupId&GT;
        &LT;&的artifactId GT;神火&LT; / artifactId的&GT;
        &LT;&版GT; 2.16 LT; /版本&GT;
        &LT;&型GT; POM&LT; /类型&GT;
     &LT; /依赖性&GT;
  &LT; /依赖和GT;
&LT; /项目&GT;


解决方案

您是不是要找添加 org.apache.maven.surefire 为POM依赖在&LT;依赖和GT;

Surefire插件的用途大多是在&LT配置; pluginManagement&GT; 部分:

 &LT;建立&GT;
  &LT; pluginManagement&GT;
    &LT;&插件GT;
      &LT;&插件GT;
        &LT;&的groupId GT; org.apache.maven.plugins&LT; /的groupId&GT;
        &LT;&的artifactId GT; Maven的万无一失,插件&LT; / artifactId的&GT;
        &LT;&版GT; 2.16 LT; /版本&GT;
      &LT; /插件&GT;
    &LT; /插件&GT;
  &LT; / pluginManagement&GT;
&LT; /构建&GT;

I created a new maven project in Eclipse that runs simple test by using both HtmlUnitDriver and FirefoxDriver to pull up a web page and check the title on the page. When I run maven command mvn test this is all that I get:

[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] ------------------------------------------------------------------------

When I run the same Maven command in Eclipse, it shows the following:

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

This is my pom.xml for those who want to check if that may be the issue:

<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>
解决方案

Did you mean to add org.apache.maven.surefire as a POM dependency under <dependencies>?

Most usages of the Surefire plugin are configured under the <pluginManagement> section:

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

这篇关于Maven的不运行测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 07:44