<bdo id='UCIdK'></bdo><ul id='UCIdK'></ul>

    1. <small id='UCIdK'></small><noframes id='UCIdK'>

        <legend id='UCIdK'><style id='UCIdK'><dir id='UCIdK'><q id='UCIdK'></q></dir></style></legend>
      1. <i id='UCIdK'><tr id='UCIdK'><dt id='UCIdK'><q id='UCIdK'><span id='UCIdK'><b id='UCIdK'><form id='UCIdK'><ins id='UCIdK'></ins><ul id='UCIdK'></ul><sub id='UCIdK'></sub></form><legend id='UCIdK'></legend><bdo id='UCIdK'><pre id='UCIdK'><center id='UCIdK'></center></pre></bdo></b><th id='UCIdK'></th></span></q></dt></tr></i><div id='UCIdK'><tfoot id='UCIdK'></tfoot><dl id='UCIdK'><fieldset id='UCIdK'></fieldset></dl></div>
        <tfoot id='UCIdK'></tfoot>

        在 docker 容器中运行 maven 集成测试

        Running maven integration test inside docker container(在 docker 容器中运行 maven 集成测试)
      2. <small id='iDgRP'></small><noframes id='iDgRP'>

          <bdo id='iDgRP'></bdo><ul id='iDgRP'></ul>
            <i id='iDgRP'><tr id='iDgRP'><dt id='iDgRP'><q id='iDgRP'><span id='iDgRP'><b id='iDgRP'><form id='iDgRP'><ins id='iDgRP'></ins><ul id='iDgRP'></ul><sub id='iDgRP'></sub></form><legend id='iDgRP'></legend><bdo id='iDgRP'><pre id='iDgRP'><center id='iDgRP'></center></pre></bdo></b><th id='iDgRP'></th></span></q></dt></tr></i><div id='iDgRP'><tfoot id='iDgRP'></tfoot><dl id='iDgRP'><fieldset id='iDgRP'></fieldset></dl></div>
              <tbody id='iDgRP'></tbody>
              1. <tfoot id='iDgRP'></tfoot>
                  <legend id='iDgRP'><style id='iDgRP'><dir id='iDgRP'><q id='iDgRP'></q></dir></style></legend>

                1. 本文介绍了在 docker 容器中运行 maven 集成测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  在运行集成测试之前,我正在使用 dockerfile-maven 插件将我的 jar 文件移动到 docker 容器中.但是 mvn verify 命令构建图像并运行集成测试,结果测试失败.有人可以在运行集成测试之前帮我运行 docker 映像吗?这样我就可以从我的集成测试文件 ping 到在 docker 容器内运行的服务.

                  以下是我的集成测试文件.

                  import java.sql.Connection;导入 java.sql.DriverManager;导入 java.sql.Statement;导入java.sql.SQLException;导入java.sql.ResultSet;导入 java.io.IOException;导入java.io.File;导入 java.util.Scanner;导入静态 org.hamcrest.MatcherAssert.*;导入静态 org.junit.matchers.JUnitMatchers.*;导入 org.junit.Assert.*;导入 com.facebook.presto.jdbc.PrestoDriver;导入 io.airlift.log.Logger;导入 org.testng.annotations.Test;类IntegrationTestIT {@测试公共无效 checkForQueryInFile() {System.out.println("这个测试方法应该运行");字符串 url = "jdbc:presto://localhost:8889/jmx/default";语句 stmt = null;尝试 {连接连接 = DriverManager.getConnection(url, "jumbo", null);stmt = connection.createStatement();字符串文件路径 = "";String sql_string = "显示模式";结果集 rs = stmt.executeQuery(sql_string);文件夹 = new File("//jars");//将此移动到常量类文件[] 文件 = 文件夹.listFiles();对于(文件文件:文件){if (file.isFile()) {file_path = file.getAbsolutePath();}}文件 log_file = new File(file_path);最终字符串扫描仪=新扫描仪(log_file).useDelimiter(\Z").next();;assertThat(扫描仪,包含字符串(sql_string));rs.close();stmt.close();连接.close();} 捕捉(IOException 异常){异常.printStackTrace();} 捕捉(SQLException sqlException){sqlException.printStackTrace();}}}

                  测试报告:

                  [INFO] 成功构建 rohitbarnwal7/presto_log_updated:0.0.1[信息] maven-failsafe-plugin:2.5:integration-test (默认) @plugin[INFO] 故障安全报告目录:/Users/rohit/workspace/presto plugins/target/failsafe-reports-------------------------------------------------------T E S T S-------------------------------------------------------运行测试套件测试运行:1,失败:1,错误:0,跳过:0,经过的时间:0.833 秒 <<<<失败!结果 :失败的测试:checkForQueryInFile(IntegrationTestIT)测试运行:1,失败:1,错误:0,跳过:0

                  TestSuite.txt 中的集成测试结果

                  测试运行:1,失败:1,错误:0,跳过:0,经过时间:0.559 秒 <<<<失败!checkForQueryInFile(IntegrationTestIT) 经过时间:0.015 秒 <<<<失败!java.lang.IllegalAccessException:类 org.testng.internal.MethodInvocationHelper 无法访问带有修饰符public"的类 IntegrationTestIT 的成员在 sun.reflect.Reflection.ensureMemberAccess(Reflection.java:102)在 java.lang.reflect.AccessibleObject.slowCheckMemberAccess(AccessibleObject.java:296)在 java.lang.reflect.AccessibleObject.checkAccess(AccessibleObject.java:288)在 java.lang.reflect.Method.invoke(Method.java:491)在 org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:85)在 org.testng.internal.Invoker.invokeMethod(Invoker.java:639)在 org.testng.internal.Invoker.invokeTestMethod(Invoker.java:816)在 org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1124)在 org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)在 org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:108)在 org.testng.TestRunner.privateRun(TestRunner.java:774)在 org.testng.TestRunner.run(TestRunner.java:624)在 org.testng.SuiteRunner.runTest(SuiteRunner.java:359)在 org.testng.SuiteRunner.runSequentially(SuiteRunner.java:354)在 org.testng.SuiteRunner.privateRun(SuiteRunner.java:312)在 org.testng.SuiteRunner.run(SuiteRunner.java:261)在 org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)在 org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)在 org.testng.TestNG.runSuitesSequentially(TestNG.java:1191)在 org.testng.TestNG.runSuitesLocally(TestNG.java:1116)在 org.testng.TestNG.run(TestNG.java:1024)在 org.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:62)在 org.apache.maven.surefire.testng.TestNGDirectoryTestSuite.execute(TestNGDirectoryTestSuite.java:141)在 org.apache.maven.surefire.Surefire.run(Surefire.java:180)在 sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)在 sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)在 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)在 java.lang.reflect.Method.invoke(Method.java:498)在 org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:350)在 org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:1021)

                  解决方案

                  辅助功能错误信息:

                  <块引用>

                  java.lang.IllegalAccessException:类 org.testng.internal.MethodInvocationHelper 无法访问带有修饰符public"的 IntegrationTestIT 类的成员

                  你必须公开你的班级才能运行测试:

                  公共类 IntegrationTestIT {...

                  测序问题:

                  如果您的集成测试在 integration-test 阶段运行,您可以在 pre-integration-test 阶段强制执行 docker 插件:

                  <执行>...<阶段>预集成测试</阶段></执行>

                  I am using dockerfile-maven plugin to move my jar file inside docker container before running integration testing. But mvn verify command builds the images and run integration test, as a result test fails. Can someone help me run the docker images before running integration test. So that I can ping to service running inside docker container from my integration test file.

                  Below is my integration test file.

                  import java.sql.Connection;
                  import java.sql.DriverManager;
                  import java.sql.Statement;
                  import java.sql.SQLException;
                  import java.sql.ResultSet;
                  import java.io.IOException;
                  import java.io.File;
                  import java.util.Scanner;
                  import static org.hamcrest.MatcherAssert.*;
                  import static org.junit.matchers.JUnitMatchers.*;
                  import org.junit.Assert.*;
                  import com.facebook.presto.jdbc.PrestoDriver;
                  import io.airlift.log.Logger;
                  import org.testng.annotations.Test;
                  
                  class IntegrationTestIT {
                  
                  @Test
                  public void checkForQueryInFile() {
                  
                      System.out.println("This test method should be run");
                      String url = "jdbc:presto://localhost:8889/jmx/default";
                  
                      Statement stmt = null;
                      try {
                          Connection connection = DriverManager.getConnection(url, "jumbo", null);
                  
                          stmt = connection.createStatement();
                          String file_path = "";
                          String sql_string = "show schemas";
                  
                          ResultSet rs = stmt.executeQuery(sql_string);
                          File folder = new File("//jars");
                          // Move this to constant class
                          File[] files = folder.listFiles(); 
                  
                          for (File file:files) {
                              if (file.isFile()) {
                                  file_path = file.getAbsolutePath();
                              }
                          }
                          File log_file = new File(file_path);
                          final String scanner = new Scanner(log_file).useDelimiter("\Z").next();;
                  
                          assertThat(scanner, containsString(sql_string));
                  
                      rs.close();
                      stmt.close();
                      connection.close();
                  
                      } catch (IOException exception) {
                          exception.printStackTrace();
                      } catch(SQLException sqlException) {
                          sqlException.printStackTrace();
                      }
                  }
                  }
                  

                  Test Report:

                  [INFO] Successfully built rohitbarnwal7/presto_log_updated:0.0.1
                  [INFO] maven-failsafe-plugin:2.5:integration-test (default) @plugin
                  [INFO] Failsafe report directory: /Users/rohit/workspace/presto plugins/target/failsafe-reports
                  
                  -------------------------------------------------------
                   T E S T S
                  -------------------------------------------------------
                  Running TestSuite
                  Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.833 sec <<< FAILURE!
                  
                  Results :
                  
                  Failed tests:
                    checkForQueryInFile(IntegrationTestIT)
                  
                  Tests run: 1, Failures: 1, Errors: 0, Skipped: 0
                  

                  Integration Test result from TestSuite.txt

                  Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.559 sec <<< FAILURE!
                  checkForQueryInFile(IntegrationTestIT)  Time elapsed: 0.015 sec  <<< FAILURE!
                  java.lang.IllegalAccessException: Class org.testng.internal.MethodInvocationHelper can not access a member of class IntegrationTestIT with modifiers "public"
                      at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:102)
                      at java.lang.reflect.AccessibleObject.slowCheckMemberAccess(AccessibleObject.java:296)
                      at java.lang.reflect.AccessibleObject.checkAccess(AccessibleObject.java:288)
                      at java.lang.reflect.Method.invoke(Method.java:491)
                      at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:85)
                      at org.testng.internal.Invoker.invokeMethod(Invoker.java:639)
                      at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:816)
                      at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1124)
                      at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
                      at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:108)
                      at org.testng.TestRunner.privateRun(TestRunner.java:774)
                      at org.testng.TestRunner.run(TestRunner.java:624)
                      at org.testng.SuiteRunner.runTest(SuiteRunner.java:359)
                      at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:354)
                      at org.testng.SuiteRunner.privateRun(SuiteRunner.java:312)
                      at org.testng.SuiteRunner.run(SuiteRunner.java:261)
                      at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
                      at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
                      at org.testng.TestNG.runSuitesSequentially(TestNG.java:1191)
                      at org.testng.TestNG.runSuitesLocally(TestNG.java:1116)
                      at org.testng.TestNG.run(TestNG.java:1024)
                      at org.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:62)
                      at org.apache.maven.surefire.testng.TestNGDirectoryTestSuite.execute(TestNGDirectoryTestSuite.java:141)
                      at org.apache.maven.surefire.Surefire.run(Surefire.java:180)
                      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
                      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
                      at java.lang.reflect.Method.invoke(Method.java:498)
                      at org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:350)
                      at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:1021)
                  

                  解决方案

                  Accessibility error message :

                  java.lang.IllegalAccessException: Class org.testng.internal.MethodInvocationHelper can not access a member of class IntegrationTestIT with modifiers "public"

                  You have to make your class public to run tests :

                  public class IntegrationTestIT {
                  ...
                  

                  Sequencing issue :

                  If your integration tests are running in the integration-test phase, you can force the execution of the docker plugin during the pre-integration-test phase :

                  <execution>
                      ...
                      <phase>pre-integration-test</phase>
                  </execution>
                  

                  这篇关于在 docker 容器中运行 maven 集成测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How can I detect integer overflow on 32 bits int?(如何检测 32 位 int 上的整数溢出?)
                  Local variables before return statements, does it matter?(return 语句之前的局部变量,这有关系吗?)
                  How to convert Integer to int?(如何将整数转换为整数?)
                  How do I create an int array with randomly shuffled numbers in a given range(如何在给定范围内创建一个随机打乱数字的 int 数组)
                  Inconsistent behavior on java#39;s ==(java的行为不一致==)
                  Why is Java able to store 0xff000000 as an int?(为什么 Java 能够将 0xff000000 存储为 int?)

                      <small id='kPsUn'></small><noframes id='kPsUn'>

                      • <bdo id='kPsUn'></bdo><ul id='kPsUn'></ul>
                          <tbody id='kPsUn'></tbody>
                        • <i id='kPsUn'><tr id='kPsUn'><dt id='kPsUn'><q id='kPsUn'><span id='kPsUn'><b id='kPsUn'><form id='kPsUn'><ins id='kPsUn'></ins><ul id='kPsUn'></ul><sub id='kPsUn'></sub></form><legend id='kPsUn'></legend><bdo id='kPsUn'><pre id='kPsUn'><center id='kPsUn'></center></pre></bdo></b><th id='kPsUn'></th></span></q></dt></tr></i><div id='kPsUn'><tfoot id='kPsUn'></tfoot><dl id='kPsUn'><fieldset id='kPsUn'></fieldset></dl></div>

                          <tfoot id='kPsUn'></tfoot><legend id='kPsUn'><style id='kPsUn'><dir id='kPsUn'><q id='kPsUn'></q></dir></style></legend>