qileilove

          blog已經(jīng)轉(zhuǎn)移至github,大家請訪問 http://qaseven.github.io/

          利用maven與testng來進行測試Maven2 基礎(chǔ)教程(3) - pom.xml 文件簡介

          Maven2 基礎(chǔ)教程(3) - pom.xml 文件簡介
          目標

          本文用以說明如何修改maven2的主要配置文件pom.xml在適應(yīng)我們的項目需要,通過本文您可以了解到

          1. 如何設(shè)定編譯參數(shù)
          2. 設(shè)定編譯環(huán)境為UTF-8編碼
          3. 添加依賴項
          4. 添加TestNG框架支持
          pom.xml 簡介

          如下是一個最基礎(chǔ)的pom.xml

          <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/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.velcro7.framework</groupId> <artifactId>velcro7-base</artifactId> <packaging>jar</packaging> <version>0.1-PROTOTYPE</version> <name>velcro7-base</name> <url>http://maven.apache.org</url> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> </dependencies></project>

          說明了項目的名稱,以及依賴于junit的項目。接下來,我們要調(diào)整一下編譯參數(shù)

          修改pom.xml調(diào)整編譯參數(shù)

          編譯參數(shù),主要通過使用設(shè)定maven-compile-plugin來實現(xiàn)
          我們加入如下配置信息

          <build> <plugins> <plugin> <artifactId>maven-compiler-plugin</artifactId> <configuration> <encoding>utf-8</encoding> <source>1.5</source> <target>1.5</target> </configuration> </plugin> </plugins></build>

          如上,可以設(shè)定編譯使用UTF-8編碼,源碼為JDK1.5的版本,目標也為JDK1.5的版本。

          設(shè)定使用UTF-8編碼

          除了編譯外,還有資源文件、javadoc等都需要告訴maven使用UTF-8編碼,我們可以設(shè)定如下兩個插件

          <plugin> <artifactId>maven-resources-plugin</artifactId> <configuration> <encoding>UTF-8</encoding> </configuration></plugin><plugin> <artifactId>maven-javadoc-plugin</artifactId> <configuration> <encoding>UTF-8</encoding> </configuration></plugin>添加TestNG的測試框架支持

          由于自動生成的項目為使用JUnit的測試框架,但是我們的項目使用TestNG的測試框架,所以我們需要調(diào)整一下項目的依賴關(guān)系,并且設(shè)定項目使用的TesgNG配置文件。
          首先刪除對于JUnit的依賴

          <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope></dependency>

          然后加入如下內(nèi)容

          <dependency> <groupId>org.testng</groupId> <artifactId>testng</artifactId> <version>5.8</version> <scope>test</scope> <classifier>jdk15</classifier></dependency>

          由于TestNG需要不同的包支持JDK15和JDK14所以在此我們要特別指定<classifier>屬性。
          如果設(shè)定了<version>屬性,maven會自動下載依賴項的對應(yīng)版本,如果沒有設(shè)置<version>屬性,Maven會自動下載最新版本。由于我們項目的開發(fā)周期比較長,所以需要指定版本,防止開發(fā)過程中由Maven自動更換我們使用的依賴庫。
          <scope>屬性,設(shè)定了依賴項的使用范圍。如果設(shè)定為test表示近測試時使用,在打包時不會打包該文件。
          接下來,我們使用插件maven-surfire-plugin設(shè)定testNG的配置文件位置,如下

          <plugin> <artifactId>maven-surefire-plugin</artifactId> <configuration> <suiteXmlFiles> <suiteXmlFile>testng.xml</suiteXmlFile> </suiteXmlFiles> </configuration></plugin>

          如上,表示使用testng.xml作為testNG的配置文件。

          結(jié)束語

          如上配置,我們最后的配置文件為

          <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/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.velcro7.framework</groupId> <artifactId>velcro7-base</artifactId> <packaging>jar</packaging> <version>0.1-PROTOTYPE</version> <name>velcro7-base</name> <url>http://maven.apache.org</url> <build> <plugins> <plugin> <artifactId>maven-resources-plugin</artifactId> <configuration> <encoding>UTF-8</encoding> </configuration> </plugin> <plugin> <artifactId>maven-javadoc-plugin</artifactId> <configuration> <encoding>UTF-8</encoding> </configuration> </plugin> <plugin> <artifactId>maven-compiler-plugin</artifactId> <configuration> <encoding>utf-8</encoding> <source>1.5</source> <target>1.5</target> </configuration> </plugin> <plugin> <artifactId>maven-surefire-plugin</artifactId> <configuration> <suiteXmlFiles> <suiteXmlFile>testng.xml</suiteXmlFile> </suiteXmlFiles> </configuration> </plugin> </plugins> </build> <dependencies> <dependency> <groupId>org.testng</groupId> <artifactId>testng</artifactId> <version>5.8</version> <scope>test</scope> <classifier>jdk15</classifier> </dependency> </dependencies></project>

          posted on 2013-02-19 14:01 順其自然EVO 閱讀(4365) 評論(0)  編輯  收藏 所屬分類: selenium and watir webdrivers 自動化測試學(xué)習(xí)

          <2013年2月>
          272829303112
          3456789
          10111213141516
          17181920212223
          242526272812
          3456789

          導(dǎo)航

          統(tǒng)計

          常用鏈接

          留言簿(55)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 丘北县| 夹江县| 滦平县| 金乡县| 措美县| 定安县| 科技| 阳山县| 乌鲁木齐县| 乌鲁木齐市| 绥德县| 沁阳市| 永平县| 长阳| 宁河县| 大连市| 滁州市| 休宁县| 五寨县| 怀来县| 浙江省| 博爱县| 井陉县| 鄯善县| 宜川县| 遂平县| 汉川市| 和田县| 驻马店市| 房山区| 岑溪市| 汉沽区| 海宁市| 金塔县| 化州市| 哈巴河县| 西峡县| 师宗县| 周至县| 景德镇市| 贡觉县|