Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
280 views
in Technique[技术] by (71.8m points)

java - maven not running integration test methods

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>

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.

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();
    }
}
}

Update 2:

Here is the maven test report from console.

[INFO] Successfully built 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] Running IntegrationTestIT

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

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

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


T E S T S

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

Results :

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You have two problems located in your tests class :

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...