前两次的总结:testng annotation生命周期 http://www.cnblogs.com/tobecrazy/p/4579414.html

testng.xml的使用和基本配置http://www.cnblogs.com/tobecrazy/p/4582173.html

在前两次的总结中,了解了一些testng基础的用法,今天了解一下使用参数的trick和使用reportng生成漂亮的测试报告


Testng 传递参数的tricks

在 http://www.cnblogs.com/tobecrazy/p/4579414.html 中我们了解到testng annotation的生命周期

@BeforeSuite->@BeforeClass->@BeforeMethod......

今天又人在说,定义过的参数在testng.xml却在case里拿不到

在testng.xml配置参数如下:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite" parallel="classes" thread-count="5">
<test verbose="2" preserve-order="true" name="TestDebug">
<parameter name="suite" value="suiteParameter" />
<parameter name="parameter1" value="parameter1" />
<parameter name="parameter2" value="123" />
<classes>
<class name="com.dbyl.tests.passParameter" />
<class name="com.dbyl.tests.TestngExample" />
</classes>
</test> <!-- Test -->
</suite> <!-- Suite -->

在测试用例中使用参数,看上去一切OK:

    /**
* This test before suite
* @param suite
*/
@Parameters({"suite"})
@BeforeSuite
public void beforeSuite(String suite)
{
System.out.println("before suite is "+suite);
}

但是 运行时却遇到这样的问题:

Parameter 'suite' is required by @Configuration on method beforeSuite but has not been marked @Optional or defined
in C:\Users\workspace\Demo\Parametertestng.xml

意思是,没有定义这个parameter(不对啊,明明定义过),后来才发现,testng.xml的parameter也是和testng的annotation中一样。若要在BeforeSuite中使用,应当在

Suite标签下定义,当然,如果这个parameter在suite中定义了,在接下来的BeforeClass BeforeMethod和Test中都可以使用

最终配置如下:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite" parallel="classes" thread-count="5">
<parameter name="suite" value="suiteParameter" />
<test verbose="2" preserve-order="true" name="TestDebug">
<parameter name="parameter1" value="parameter1" />
<parameter name="parameter2" value="123" />
<classes>
<class name="com.dbyl.tests.passParameter" />
<class name="com.dbyl.tests.TestngExample" />
</classes>
</test> <!-- Test -->
</suite> <!-- Suite -->

使用Reportng

ReportNG is a simple HTML reporting plug-in for the TestNG unit-testing framework. It is intended as a replacement for the default TestNG HTML report. The default report is comprehensive but is not so easy to understand at-a-glance. ReportNG provides a simple, colour-coded view of the test results.

reportng 是一个简单的testng 的生成html格式报告插件,是为了取代testng 默认的 html report.tesng默认的report不容易理解,也不太美观。reportng提高简单的,多彩的测试结果的视图.

那么问题就来了,怎么使用?

1.首先安装testng

2.下载reportng jar包

  http://pan.baidu.com/s/1i3KdlQH

3.添加到project

build path

  注意:需要同时引入google guice

  http://pan.baidu.com/s/1pJkFezT

4.配置reportng

  • 禁用testng default listeners
  • 在define listener中添加:org.uncommons.reportng.HTMLReporter

最后run as test suite

在html目录就能看到漂亮的report

如果咋ant里使用,需要这样 :

    <testng  classpathref="runpath"  outputDir="test-output"
haltonfailure="true"
useDefaultListeners="false"
listeners="org.uncommons.reportng.HTMLReporter,org.testng.reporters.FailedReporter" >
<xmlfileset dir="${basedir}" includes="Parametertestng.xml"/>
<jvmarg value="-Dfile.encoding=UTF-8" />
<sysproperty key="org.uncommons.reportng.title" value="AutoMation TestReport" />
</testng>

testng 教程之使用参数的一些tricks配合使用reportng的更多相关文章

  1. 手把手教从零开始在GitHub上使用Hexo搭建博客教程(二)-Hexo参数设置

    前言 前文手把手教从零开始在GitHub上使用Hexo搭建博客教程(一)-附GitHub注册及配置介绍了github注册.git相关设置以及hexo基本操作. 本文主要介绍一下hexo的常用参数设置. ...

  2. TestNG教程

    TestNG教程 http://www.yiibai.com/testng/2013/0916311.html TestNG,3种执行方式: 1.ant(build.xml) 2.Eclipse(安装 ...

  3. TestNG教程网站

    比较简明的一些TestNG教程网站 : https://www.jianshu.com/p/74816a200221 http://www.yiibai.com/testng/parameterize ...

  4. testng 教程

    Testng 简介: Testng是一套开源测试框架,是从Junit继承而来,testng意为test next generation,主要有以下特性: annotations  注释,如 @test ...

  5. SOAPUI使用教程-了解REST参数

    1.2.资源参数 在这一节中,我们更为详细的看看提供给你不同类型的REST参数.有五种类型的可用参数:QUERY, HEADER, TEMPLATE, MATRIX and PLAIN. 所有参数可以 ...

  6. Shell编程基础教程7--脚本参数的传递

    7.脚本参数的传递    7.1.shift命令        简介:            shift n        每次将参数位置向左偏移n位        例子 #!/bin/bash us ...

  7. springBoot系列教程06:参数验证及验证信息国际化

    在springboot应用中要验证参数是否正确很简单,web应用已经包含了validation的 1.定义需要被验证的参数实体,并用注解标明错误类别和错误信息 package com.xiao.dom ...

  8. metasploit 教程之基本参数和扫描

    前言 首先我也不知道我目前的水平适不适合学习msf. 在了解一些msf之后,反正就是挺想学的.就写博记录一下.如有错误的地方,欢迎各位大佬指正. 感激不尽.! 我理解的msf msf全程metaspl ...

  9. Shell教程 之传递参数

    1.Shell传递参数 我们可以在执行 Shell 脚本时,向脚本传递参数,脚本内获取参数的格式为:$n.n 代表一个数字, 0 为执行的文件名,1 为执行脚本的第一个参数,2 为执行脚本的第二个参数 ...

随机推荐

  1. discuz论坛插件设计学习培训视频全套教程

    discuz模板跟插件开发的教程比较少,特搜集给大家学习插件做的好,在dsicuz应用中心出 售也是可以卖不少的呢 教程目录:第1章  本章的标题第1节Discuz! X 产品安装与配置第2节模板风格 ...

  2. 微信小程序之本地缓存(十)

    [未经作者本人同意,请勿以任何形式转载] 目前,微信给每个小程序提供了10M的本地缓存空间(哎哟妈呀好大) 有了本地缓存,你的小程序可以做到: 离线应用(已测试在无网络的情况下,可以操作缓存数据) 流 ...

  3. Unix NetWork Programming(unix环境编程)——环境搭建(解决unp.h等源码编译问题)

    此配置实例亲测成功,共勉,有问题大家留言. 环境:VMware 10 + unbuntu 14.04 为了unix进行网络编程,编程第一个unix程序时遇到的问题,不能包含unp.h文件,这个感觉和a ...

  4. vue2.0 开发实践总结之入门篇

    vue2.0 据说也出了很久了,博主终于操了一次实刀. 整体项目采用  vue +  vue-router +  vuex (传说中的vue 全家桶 ),构建工具使用尤大大推出的vue-cli 后续文 ...

  5. 跟我从零基础学习Unity3D开发--资源打包篇(AssetBundle)

    好久没更新了,一直在加班敢项目进度.这里和关注我的博客的童鞋表示一下歉意!这里有我录的Unity3D从零开始的视频教程大家可以关注一下:http://www.imooc.com/view/555  视 ...

  6. CommandBehavior.CloseConnection

    cmd.commandTimeout设置为了1秒,sql执行了很长时间还没有超时, cmd.ExecuteReader(CommandBehavior.CloseConnection)这样就会立马重现 ...

  7. RecyclerView的使用(三)

    上个小结中介绍了如何使用RecyclerView显示不同的数据展示样式(瀑布流也是可以显示的,从GridView改就好) 本节来为RecyclerView的item添加监听事件. RecyclerVi ...

  8. 内存溢出VS内存泄漏

    内存溢出是指用户在对其数据缓冲区操作时,超过了其缓冲区的边界,尤其是对缓冲区进行写操作缓冲区的溢出很可能导致程序的异常. 内存泄露是指程序在运行过程中动态申请的内存空间不再使用后没有及时释放,从而很可 ...

  9. iOS开发小技巧--iOS程序进入后台运行的实现

    iOS程序进入后台运行的实现 视频中看到老师用的iOS7,代码中有开启timer,无限请求数据的功能,但是切换到后台,代码就不打印了 自己用的iOS9,进入后台还是可以打印的,再次进入前台也可以正常运 ...

  10. 【BZOJ 1065】【Vijos 1826】【NOI 2008】奥运物流

    http://www.lydsy.com/JudgeOnline/problem.php?id=1065 https://vijos.org/p/1826 好难的题啊TWT ∈我这辈子也想不出来系列~ ...