美文网首页
maven运行testng的pom文件

maven运行testng的pom文件

作者: tyoko | 来源:发表于2017-08-25 02:21 被阅读0次

maven官方文档

http://maven.apache.org/plugins/index.html

在pom.xml文件中增加testng的maven dependencies,可以选择最新版本.可以去以下的网站搜索最新版本的maven库

search.maven.org
image.png

maven给testng提供了3个插件用于扩展:resource、compile、surefire

在pom文件中引用testng.xml,使用surefire插件;引用compile插件可以解决编码、编译器版本问题

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>TestngDemo</groupId>
    <artifactId>TestngDemo</artifactId>
    <version>1.0-SNAPSHOT</version>
    <properties>
        <!--解决编码问题-->
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <!-- https://mvnrepository.com/artifact/org.testng/testng -->
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>6.11</version>
            <scope>test</scope>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.6.1</version>
                <configuration>
                    <verbose>true</verbose>
                    <!--在新的虚拟机中开启-->
                    <fork>true</fork>
                    <compilerVersion>1.8</compilerVersion>
                    <encoding>utf-8</encoding>
                    <!--源代码的编译-->
                    <source>1.8</source>
                    <target>1.8</target>

                </configuration>

                </plugin>
                <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.20</version>
                <configuration>
                    <suiteXmlFiles>
                        <!--可以添加多个xml文件-->
                        <file>testng.xml</file>
                    </suiteXmlFiles>

                    <properties>
                        <property>

                            <!--日志级别,0-10,10最详细-->
                            <name>surefire.testng.verbose</name>
                            <value>5</value>
                            <!--允许并行-->
                            <name>suitethreadpoolsize</name>
                            <value>2</value>
                            
                        </property>
                    </properties>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

修改编码格式,使用resource插件。官网给出两种方案,最好的是在pom文件中增加<properties>,还有一个是在<bulid><plugins><plugin><configuration><encoding>UTF-8<...

image.png

相关文章

网友评论

      本文标题:maven运行testng的pom文件

      本文链接:https://www.haomeiwen.com/subject/qvbydxtx.html