【问题标题】:How to avoid running test cases twice using maven command如何避免使用 maven 命令两次运行测试用例
【发布时间】:2019-06-27 05:52:56
【问题描述】:

我正在开发一个测试自动化项目。我在 Eclipse 中使用 testNg 插件运行测试用例。没关系。但是当我使用 mvn test 命令运行测试时,maven 会运行两次测试用例。当它从詹金斯执行时,事情变得更糟。完成所有测试用例需要很长时间。 我该如何解决这个问题。我的 POM 文件如下-

请告诉我 mvn 命令如何只运行一次测试用例。 谢谢 皮疹

<properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>

    <build>
        <resources>
            <resource>
                <directory>src/test/java</directory>
                <includes>
                    <include>**/*.java</include>
                </includes>
            </resource>
            <resource>
                <directory>src/test/resources/pageproperty</directory>
                <includes>
                    <include>**/*.properties</include>
                </includes>
            </resource>
        </resources>
        <plugins>
            <plugin>
                <!-- Build an executable JAR -->
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>3.1.0</version>
                <configuration>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <classpathPrefix>lib/</classpathPrefix>
                            <mainClass>main/InspirxTest</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <webResources>
                        <resource>
                            <!-- this is relative to the pom.xml directory -->
                            <directory>src/main/java/resources/InspirxTestAutomation</directory>
                        </resource>
                    </webResources>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.19.1</version>
                <configuration>
                    <useSystemClassLoader>false</useSystemClassLoader>
                    <!-- Configuring the test suites to check executed fine -->
                    <suiteXmlFiles>
                        <suiteXmlFile>${project.basedir}/testNG.xml</suiteXmlFile>
                        <suiteXmlFile>testNG.xml</suiteXmlFile>
                    </suiteXmlFiles>
                    <skip>false</skip>
                </configuration>
            </plugin>
            <!-- <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>3.0.0-M3</version>
            </plugin> -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-install-plugin</artifactId>
                <executions>
                    <execution>
                        <id>install-ixlib-junitsupport</id>
                        <phase>clean</phase>
                        <configuration>
                            <file>${basedir}/lib/forLocalRepos/ixlib-junitsupport.jar</file>
                            <repositoryLayout>default</repositoryLayout>
                            <groupId>com.inspirx</groupId>
                            <artifactId>ixlib-junitsupport</artifactId>
                            <version>5.2.3</version>
                            <packaging>jar</packaging>
                            <generatePom>true</generatePom>
                        </configuration>
                        <goals>
                            <goal>install-file</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>install-ojdbc</id>
                        <phase>clean</phase>
                        <configuration>
                            <file>${basedir}/lib/forLocalRepos/ojdbc8.jar</file>
                            <repositoryLayout>default</repositoryLayout>
                            <groupId>com.inspirx</groupId>
                            <artifactId>ojdbc8</artifactId>
                            <version>8</version>
                            <packaging>jar</packaging>
                            <generatePom>true</generatePom>
                        </configuration>
                        <goals>
                            <goal>install-file</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
    <dependencies>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi</artifactId>
            <version>3.17</version>
        </dependency>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
            <version>3.17</version>
        </dependency>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-scratchpad</artifactId>
            <version>3.17</version>
        </dependency>

        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>6.11</version>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>3.4.0</version>
        </dependency>
        <dependency>
            <groupId>org.openqa.selenium.server</groupId>
            <artifactId>selenium-server-coreless</artifactId>
            <version>1.0-20081010.060147</version>
        </dependency>

        <dependency>
            <groupId>javax.mail</groupId>
            <artifactId>mail</artifactId>
            <version>1.4.5</version>
        </dependency>
        <dependency>
            <groupId>com.googlecode.json-simple</groupId>
            <artifactId>json-simple</artifactId>
            <version>1.1</version>
        </dependency>
        <dependency>
            <groupId>joda-time</groupId>
            <artifactId>joda-time</artifactId>
            <version>2.10.1</version>
        </dependency>
        <dependency>
            <groupId>com.inspirx</groupId>
            <artifactId>ixlib-junitsupport</artifactId>
            <version>5.2.3</version>
        </dependency>
        <dependency>
            <groupId>org.dbunit</groupId>
            <artifactId>dbunit</artifactId>
            <version>2.4.9</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.postgresql/postgresql -->
        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <version>42.2.5</version>
        </dependency>
        <dependency>
            <groupId>com.inspirx</groupId>
            <artifactId>ojdbc8</artifactId>
            <version>8</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.6.1</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-log4j12 -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.6.1</version>
            <scope>test</scope>
        </dependency>
        <!-- https://mvnrepository.com/artifact/log4j/log4j -->
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>


        <!-- https://mvnrepository.com/artifact/commons-lang/commons-lang -->
        <dependency>
            <groupId>commons-lang</groupId>
            <artifactId>commons-lang</artifactId>
            <version>2.4</version>
        </dependency>

    </dependencies>
</project>

【问题讨论】:

  • 你能分享一些日志吗?我不明白为什么测试应该运行两次。你用什么命令来构建 (clean install?)
  • 遵循约定优于配置。为什么要在src/test/java 中配置资源。测试资源属于src/test/resources...

标签: maven selenium


【解决方案1】:

存在多个插件,可能会启用多个执行。 'maven-surefire-plugin' 足以运行测试,您可以尝试一一评论其他插件并检查哪个插件再次运行测试。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-04-23
    • 2016-01-25
    • 1970-01-01
    • 2011-01-15
    相关资源
    最近更新 更多