天天看點

TestNg測試架構使用

 安裝eclipse插件

  for eclipse 3.4 and above, enter http://beust.com/eclipse.

  for eclipse 3.3 and below, enter http://beust.com/eclipse1.

<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>com.homeinns.web</groupid>

<artifactid>homeinns-testng</artifactid>

<version>0.0.1-snapshot</version>

<packaging>jar</packaging>

<name>homeinns-testng</name>

<url>http://maven.apache.org</url>

<properties>

<project.build.sourceencoding>utf-8</project.build.sourceencoding>

</properties>

<dependencies>

<dependency>

<groupid>org.testng</groupid>

<artifactid>testng</artifactid>

<version>6.1.1</version>

<scope>test</scope>

</dependency>

</dependencies>

<build>

<plugins>

<plugin>

<groupid>org.apache.maven.plugins</groupid>

<artifactid>maven-surefire-plugin</artifactid>

<version>2.16</version>

<configuration>

<suitexmlfiles>

<suitexmlfile>testng.xml</suitexmlfile>

<!-- <suitexmlfile>src/test/resources/testng.xml</suitexmlfile> -->

</suitexmlfiles>

</configuration>

</plugin>

</plugins>

</build>

</project>

 配置testng suite

<?xml version="1.0" encoding="utf-8"?>

<!doctype suite system "http://testng.org/testng-1.0.dtd">

<suite name="suite" parallel="none">

<!--enabled="true"讓測試生效,也可根據情況關閉某些測試 -->

<test name="test" enabled="true">

<!--指定參數 -->

<parameter name="name" value="irving" />

<parameter name="sex" value="man" />

<!--指定測試包 -->

<packages>

<package name="com.homeinns.web.testng.*" />

</packages>

<!--指定測試類 -->

<classes>

<class name="com.homeinns.web.testng.apptest" />

</classes>

</test> <!-- test -->

</suite> <!-- suite -->

testng注解配置

public class ngtest {

@test

public void f() {

}

@test(

// 在指定的時間内啟用3個線程并發測試本方法10次

threadpoolsize = 3, invocationcount = 10, timeout = 10000,

// 等待測試方法t0測試結束後開始本測試

dependsonmethods = { "f" },

// 指定測試資料源class和資料源名稱(參考注解@dataprovider),傳回幾條資料會跑測試方法幾次

dataprovider = "generate", dataproviderclass = generatorrandomnum.class,

// 分組名稱

groups = { "checkin-test" })

// 讀取配置檔案中的參數,配置如上,用@optional設定預設值

@parameters({ "name" })

public void f1(@optional("name") string name) {

  測試報告

  運作測試後 在my-testng/test-output/ 目錄下(maven \target\surefire-reports)

  gradle配置

subprojects {

apply plugin: 'java'

// disable the test report for the individual test task

test {

reports.html.enabled = false

task testreport(type: testreport) {

destinationdir = file("$builddir/reports/alltests")

//include the results from the `test` task in all subprojects

reporton subprojects*.test

}grouping testng tests

usetestng {

excludegroups 'integrationtests'

includegroups 'unittests'

最新内容請見作者的github頁:http://qaseven.github.io/

繼續閱讀