当前位置: 首页 > 面试题库 >

Maven未运行测试

凤高翰
2023-03-14
问题内容

我在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为POM依赖项<dependencies>吗?

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>


 类似资料:
  • 有没有人能告诉我为什么我不能使用Maven运行任何测试。 已配置SureFire插件 在runner类下设置胶合代码 “测试”被追加到runner类 注意:如果我将文件作为Junit运行,那么它可以正确地运行所有场景。只有当我使用Maven运行它时,才不会运行任何测试。

  • 我有一个rest Spring Boot rest API,我想测试它。我可以在Eclipse中手动运行测试(不使用maven,并通过将应用程序作为JUnit测试运行),它运行良好并显示结果,但是不能“工作”,如下所示。 以下是我的POM文件:

  • 我正在进行集成测试,但由于某些原因,maven failsafe插件没有运行。下面是用于集成测试的概要文件。测试类的名称是AppSmokeTest。java@测试正在用于测试。 我看过多篇关于这个问题的帖子 我试着在build标签中运行插件。 我尝试添加 我也尝试过运行maven failsafe插件2.18.1版,因为我看到有人认为它对他们有用。

  • 问题内容: 当我使用以下命令在Maven中运行单个测试时: 我得到以下结果: 它在几分钟前工作了,但是现在由于某种原因停止了工作。在运行测试之前,我尝试运行几次,但没有帮助。 测试看起来像这样: }} 更新: 这是由于将此依赖项添加到POM: 当我删除它时,一切正常。即使我添加以下两个依赖关系而不是上一个依赖关系,一切也都可以正常工作: 真奇怪 问题答案: 您可能正在类路径上的某个地方拾取了JUn

  • 我有一个Maven/SpringBoot2.3。3应用JUnit 5和Cucumber(v6.5.1)测试。 问题是,我可以通过Maven运行OK单元测试和集成测试,但它不运行Cucumber。 cucumber赛跑者: Cucumber Spring上下文配置: 步骤: 我在Maven pom中使用Surefire和故障保护。xml:https://github.com/danieldestro

  • 你好,我正在尝试使用Maven运行一个JUnit测试。 [信息]没有要编译的内容-所有类都是最新的 [信息] [信息]--maven-surefire-plugin:2.10:test(default-test)@uitests-core-- 我不知道为什么它不能运行我的测试。请帮帮我。