maven没有运行集成测试方法

时间:2018-02-06 09:36:17

标签: java maven plugins testng

我正在使用dockerfile-maven插件在我的docker容器和maven-failsafe-plugin中移动jar文件来启动我的集成测试。但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>

我已将Integration测试类命名为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 [INFO] --- maven-surefire-plugin:2.20.1:test(integration-test)@plugin

[INFO] 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

1 个答案:

答案 0 :(得分:1)

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

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