【问题标题】:maven not running integration test methodsmaven 没有运行集成测试方法
【发布时间】:2018-02-07 20:56:24
【问题描述】:

我正在使用 dockerfile-maven 插件将 jar 文件移动到我的 docker 容器中,并使用 maven-failsafe-plugin 来启动我的集成测试。但是 maven 从不运行集成测试方法。下面是我的 pom.xml

        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>2.20.1</version>
          <configuration>
            <excludes>
              <exclude>**/*IntegrationTestIT.java</exclude>
            </excludes>
          </configuration>
          <executions>
            <execution>
              <id>integration-test</id>
              <goals>
                <goal>test</goal>
              </goals>
              <phase>integration-test</phase>
              <configuration>
                <excludes>
                  <exclude>none</exclude>
                </excludes>
                <includes>
                  <include>**/*IntegrationTestIT.java</include>
                </includes>
              </configuration>
            </execution>
          </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-failsafe-plugin</artifactId>
            <version>2.12</version>
            <executions>
                <execution>
                <goals>
                    <goal>integration-test</goal>
                </goals>
                <configuration>
                    <includes>
                        <include>**/*.java</include>
                    </includes>
                </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>com.spotify</groupId>
            <artifactId>dockerfile-maven-plugin</artifactId>
            <version>1.3.7</version>
            <executions>
                <execution>
                    <id>default</id>
                    <goals>
                        <goal>build</goal>
                        <goal>push</goal>
                    </goals>
                </execution>

            </executions>
            <configuration>
                <repository>rohitbarnwal7/presto_log_updated</repository>
                <tag>${project.version}</tag>
                <buildArgs>
                    <JAR_FILE>plugin-${project.version}-jar-with-dependencies.jar</JAR_FILE>
                </buildArgs>
            </configuration>
        </plugin>

我已将我的集成测试类命名为 IntegrationTestIT.java 并按照 this 集成 dockerfile maven 插件。

我已经被这个问题困扰了一段时间,任何帮助将不胜感激。

更新 1: 添加我的 IntegrationTestIT.java 文件。在这里,我尝试与 presto 连接并运行查询以检查它们是否已记录到文件中。(Maven 项目是一个 presto 插件,假设记录所有在 presto 服务器上运行的 presto 查询。)

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.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.*;
import static org.junit.matchers.JUnitMatchers.*;
import io.prestodb.tempto.query.QueryExecutor;
import static io.prestodb.tempto.context.ThreadLocalTestContextHolder.testContext;
import io.prestodb.tempto.AfterTestWithContext;
import io.prestodb.tempto.BeforeTestWithContext;
import org.junit.Assert.*;
import com.facebook.presto.jdbc.PrestoDriver;
import io.airlift.log.Logger;
import org.testng.annotations.*;


class IntegrationTestIT{

@Test
void checkForQueryInFile() {

    System.out.println("This test method should be run");

    String url = "jdbc:presto://sandbox:8080/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();
    }
}
}

更新 2:

这是来自控制台的 Maven 测试报告。

[INFO] 成功构建 rohitbarnwal7/presto_log_updated:0.0.1 [信息] --- maven-surefire-plugin:2.20.1:test (integration-test) @plugin

[信息] T E S T S

[INFO] 运行 IntegrationTestIT

[INFO] 测试运行:0,失败:0,错误:0,跳过:0,经过时间:0.804 秒 - 在 IntegrationTestIT 中

[INFO] 结果: [INFO] 测试运行:0,失败:0,错误:0,跳过:0

[INFO] --- maven-failsafe-plugin:2.12:integration-test (默认) @plugin --- [INFO] 故障安全报告目录:/Users/rohit/workspace/work/presto-plugins/target/failsafe-reports


T E S T S

运行 IntegrationTestIT 配置TestNG:org.apache.maven.surefire.testng.conf.TestNGMapConfigurator@7960847b 测试运行:0,失败:0,错误:0,跳过:0,经过的时间:0.469 秒

结果:

测试运行:0,失败:0,错误:0,跳过:0

【问题讨论】:

  • 你调用测试的 maven 命令是什么?你试过“mvn verify”
  • 是的,我正在使用 mvn verify
  • 你能告诉我们你的IntegrationTestIT文件里面有什么吗?
  • 更新了相关信息,也添加了 maven 报告。

标签: java maven plugins testng


【解决方案1】:

您的测试类中有两个问题:

  1. 类和测试方法必须是公开的。
  2. 您的 checkForQueryInFile 方法缺少 TestNG @Test 注释。

【讨论】:

  • 抱歉,它不起作用。得到了同样的专家报告。 [INFO] --- maven-failsafe-plugin:2.12:integration-test (default) @plugin --- 运行 IntegrationTestIT 配置 TestNG:org.apache.maven.surefire.testng.conf.TestNGMapConfigurator@7960847b 测试运行:0 ,失败:0,错误:0,跳过:0,经过时间:0.492 秒结果:测试运行:0,失败:0,错误:0,跳过:0
  • 我的错,你正在使用 TestNG,我已经编辑了我的答案。
  • 感谢测试运行。我还需要公开 checkForQueryInFile 方法并将 maven-failsafe 版本更改为 2.5。但这是另一个问题stackoverflow.com/questions/48657869/…
  • 在我的回答中添加了可见性问题
  • 当然,在启动集成测试之前运行 docker build 有什么想法吗?
猜你喜欢
  • 1970-01-01
  • 2023-01-09
  • 1970-01-01
  • 1970-01-01
  • 2014-03-13
  • 1970-01-01
  • 2010-11-02
  • 2019-05-08
相关资源
最近更新 更多