【问题标题】:Build Failure when running the Project through maven install通过 maven install 运行项目时构建失败
【发布时间】:2017-05-24 06:52:06
【问题描述】:

Right Click Project>>Run As>>Maven Install尝试在 Eclipse 中运行项目

我的 src\\tests 文件夹中只有 2 个测试用例,并且两个测试用例都运行良好。测试完成后,在控制台中出现构建失败。

错误:-未能执行目标 org.apache.maven.plugins:maven-surefire-plugin:2.19.1:test 项目 selenium-project 上的(默认测试):执行默认测试 目标 org.apache.maven.plugins:maven-surefire-plugin:2.19.1:test failed: 分叉进程出错 org.openqa.selenium.remote.SessionNotFoundException

请参考以下截图

【问题讨论】:

  • 你在使用 testNG 吗?
  • @RAMANDOGRA 你能考虑更新你的 maven 项目文件夹结构,pom.xml 和你的代码块吗?谢谢
  • @TrimantraSoftwareSolution 是的,我正在使用 TestNG

标签: eclipse maven selenium maven-install-plugin


【解决方案1】:

我有以下方式使用 Maven 从 testing.xml 文件执行您的测试

在项目根目录中添加一个Testing.xml 文件。内容会像

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="TestSuit">
  <test name="MyTest">
         <classes>      
                        <class name="package.subpackage.TestClassName"/>            
         </classes> 
  </test>
</suite>

pom.xml&lt;dependencies&gt; 标记上方添加下面的代码

     <!-- Following plugin executes the testing tests  -->
        <plugin>
           <groupId>org.apache.maven.plugins</groupId>
           <artifactId>maven-surefire-plugin</artifactId>
           <version>2.12.4</version>
               <configuration>    
                <!-- Suite testng xml file to consider for test execution -->
                 <suiteXmlFiles>
                     <suiteXmlFile>testng.xml</suiteXmlFile>
                 </suiteXmlFiles>
               </configuration>                       
        </plugin> 

          <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>     
     </plugins>
  </build>

执行以下步骤

右键单击项目 > 运行方式 > Maven 清理

然后

右击项目>运行方式>Maven构建

然后

右击项目>运行方式>Maven测试

【讨论】:

  • 谢谢它终于为我工作了。实际上我的 pom.xml 中缺少编译器-plugin
  • 上述更改在独立运行 Project 时运行良好,但在从 Jenkins 运行时,我的构建失败。这是控制台输出错误。 java.lang.reflect.InvocationTargetException 引起:java.lang.NoSuchFieldError: org.apache.maven.cli.DefaultMavenExecutionRequestBuilder.settings() 的 DEFAULT_USER_SETTINGS_FILE org.jvnet 的 org.apache.maven.cli.DefaultMavenExecutionRequestBuilder.getMavenExecutionRequest()。 org.jvnet.hudson.maven3.launcher.Maven33Launcher.main() 上的 hudson.maven3.launcher.Maven33Launcher.getMavenExecutionRequest() 无法解析 POM
【解决方案2】:

将以下代码添加到您的 pom.xml。

<plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>2.19.1</version>
        </plugin>
  </plugins>

让我知道它是否有效。

【讨论】:

  • 错误说明了一切Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.19.1 指出 maven-surefire-plugin2.19.1 已经安装。谢谢
  • 这是我的 POM.xml
猜你喜欢
  • 1970-01-01
  • 2022-08-10
  • 2015-05-10
  • 2016-10-19
  • 2020-10-21
  • 1970-01-01
  • 1970-01-01
  • 2019-07-21
  • 2017-06-13
相关资源
最近更新 更多