maven没有运行集成测试方法 [英] maven not running integration test methods

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

问题描述

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

I am using dockerfile-maven plugin to move jar file inside my docker container and maven-failsafe-plugin to initiate my integration testing. But maven never run integration test methods. Below is my 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>

我已将Integration测试类命名为IntegrationTestIT.java并遵循这个来整合dockerfile maven插件。

I have named my Integration test class as IntegrationTestIT.java and followed this to integrate dockerfile maven plugin.

我一直坚持这个问题,任何帮助都会受到高度赞赏。

I have been stuck with this problem for a while, any help would be highly appreciated.

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

Update 1: Adding my IntegrationTestIT.java file. Here I am trying to connect with presto and run a query to check if they are logged to a file.(Maven project is a presto plugin which is suppose to log all presto queries ran on the presto server.)

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测试报告。

Here is the maven test report from console.

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

[INFO] Successfully built rohitbarnwal7/presto_log_updated:0.0.1 [INFO] --- maven-surefire-plugin:2.20.1:test (integration-test) @plugin

[INFO] TESTS

[INFO] T E S T S

[INFO]运行IntegrationTestIT

[INFO] Running IntegrationTestIT

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

[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.804 s - in IntegrationTestIT

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

[INFO] Results: [INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0

[INFO] --- maven-failsafe-plugin:2.12:integration-test(默认)@plugin ---
[INFO]失败保险报告目录:/ Users / rohit / workspace / work / presto-plugins / target / failsafe-reports

[INFO] --- maven-failsafe-plugin:2.12:integration-test (default) @plugin --- [INFO] Failsafe report directory: /Users/rohit/workspace/work/presto-plugins/target/failsafe-reports

运行IntegrationTestIT
使用以下命令配置TestNG:org.apache.maven.surefire.testng.conf.TestNGMapConfigurator@7960847b
测试运行: 0,失败:0,错误:0,跳过:0,已过去时间:0.469秒

Running IntegrationTestIT Configuring TestNG with: org.apache.maven.surefire.testng.conf.TestNGMapConfigurator@7960847b Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.469 sec

结果:

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

Tests run: 0, Failures: 0, Errors: 0, Skipped: 0

推荐答案

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

You have two problems located in your tests class :


  1. 班级和测试方法必须公开。

  2. 你的 checkForQueryInFile 方法缺少TestNG @Test 注释。

  1. The class and the test method must be public.
  2. Your checkForQueryInFile method is missing the TestNG @Test annotation.

这篇关于maven没有运行集成测试方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆