Chinaunix首页 | 论坛 | 博客
  • 博客访问: 19877607
  • 博文数量: 679
  • 博客积分: 10495
  • 博客等级: 上将
  • 技术积分: 9308
  • 用 户 组: 普通用户
  • 注册时间: 2006-07-18 10:51
文章分类

全部博文(679)

文章存档

2012年(5)

2011年(38)

2010年(86)

2009年(145)

2008年(170)

2007年(165)

2006年(89)

分类: 项目管理

2009-08-27 10:42:46

§2    创建测试数据

File information

2009-8-27

磁针石:xurongzhong#gmail.com

博客:oychw.cublog.cn



§2.1 测试数据语法

     文件和目录:

       在测试用例文件中创建测试用例,并自动生成test suite。多个测试用例文件所在的目录组成高级的test suite目录。test suite目录可以嵌套,可以有特殊的初始化文件。

       除此之外还有测试库包含低级关键字;拥有变量和高级用户关键字的资源文件;更方便创建变量的变量文件。

 

     支持的文件格式:

       采用表格的形式,HTMLTSVreST。基于扩展名选择:.html, .htm and .xhtml for HTML, .tsv for TSV, and .rst or .rest for reStructuredText.

       HTML格式举例:

Setting

Value

Value

Value

Library

OperatingSystem

 

 

 

 

 

 

 

Variable

Value

Value

Value

${MESSAGE}

Hello, world!

 

 

 

 

 

 

 

Test Case

Action

Argument

Argument

My Test

[Documentation]

Example test

 

 

Log

${MESSAGE}

 

 

My Keyword

/tmp

 

 

 

 

 

Another Test

Should Be Equal

${MESSAGE}

Hello, world!

 

Keyword

Action

Argument

Argument

My Keyword

[Arguments]

${path}

 

 

Directory Should Exist

${path}

 

 

       可以使用WORD或者Robot IDE编辑。

       其他格式暂略。

 

     测试数据表:

Table name

Used for

Aliases

Setting table

1) Importing test libraries, resource files and variable files

2) Defining metadata for test suites and test cases

Setting, Settings, Metadata

Variable table

Defining variables that can be used elsewhere in the test data

Variable, Variables

Test case table

Creating test cases from available keywords

Test Case, Test Cases

Keyword table

Creating user keywords from existing lower-level keywords

Keyword, Keywords, User Keyword, User Keywords

 

     解析数据的规则:

空的表格单元要使用${EMPTY}或者\。空格有${SPACE}

 

参数等续行的方法:

Setting

Value

Value

Value

Default Tags

tag-1

tag-2

tag-3

...

tag-4

tag-5

tag-6

 

Variable

Value

Value

Value

@{LIST}

this

list

has

...

quite

many

items

 

Test Case

Action

Argument

Argument

Argument

Example

[Documentation]

Documentation

for this

test case.

 

...

This can get

quite

long...

 

[Tags]

t-1

t-2

t-3

 

...

t-4

t-5

 

 

Do X

one

two

three

 

...

four

five

six

 

${var} =

Get X

1

2

 

...

3

4

5

 

...

6

 

 

 

 

§2.2 创建测试用例       

     测试用例语法

测试用例示例:

Test Case

Action

Argument

Argument

Valid Login

Open Login Page

 

 

 

Input Name

demo

 

 

Input Password

mode

 

 

Submit Credentials

 

 

 

Welcome Page Should Be Open

 

 

 

 

 

 

Setting Variables

Do Something

first argument

second argument

 

${value} =

Get Some Value

 

 

Should Be Equal

${value}

Expected value

 

数据驱动举例:

Test Case

 

User Name

Password

Invalid User Name

Login With Invalid Credentials Should Fail

invalid

mode

Invalid Password

Login With Invalid Credentials Should Fail

demo

invalid

Invalid User Name And Password

Login With Invalid Credentials Should Fail

invalid

whatever

Empty User Name

Login With Invalid Credentials Should Fail

 

mode

Empty Password

Login With Invalid Credentials Should Fail

demo

\

Empty User Name And Password

Login With Invalid Credentials Should Fail

 

\

 

测试用例表设置:

示例:

Test Case

Action

Argument

Argument

Test With Settings

[Documentation]

Another dummy test

 

 

[Tags]

dummy

owner-johndoe

 

Log

Hello, world!

 

主要有[Documentation][Tags][Setup], [Teardown] [Precondition] and [Postcondition][Timeout]等标识。

 

     测试用例名字和文档

 

Test Case

Action

Argument

Argument

Simple

[Documentation]

Simple documentation

 

 

No Operation

 

 

Splitting

[Documentation]

This documentation is a bit longer and

it has been split into several columns.

 

No Operation

 

 

Formatting

[Documentation]

*This is bold*, _this italic_ and

here is a link:

 

No Operation

 

 

Variables

[Documentation]

Executed at ${HOST} by ${USER}

 

 

No Operation

 

 

 

一般情况下是不需要文档的。

     标签测试用例

Force Tags

Default Tags

[Tags]

--settag

Set Tags and Remove Tags

 

Tagging example

Setting

Value

Value

Value

Force Tags

req-42

 

 

Default Tags

owner-john

smoke

 

 

Variable

Value

Value

Value

${HOST}

10.0.1.42

 

 

 

Test Case

Action

Argument

Argument

No own tags

[Documentation]

This test has tags

owner-john, smoke, req-42

 

No Operation

 

 

 

 

 

 

With own tags

[Documentation]

This test has tags

not_ready, owner-mrx, req-42

 

[Tags]

owner-mrx

not_ready

 

No Operation

 

 

 

 

 

 

Own tags with variables

[Documentation]

This test has tags

host-10.0.1.42, req-42

 

[Tags]

host-${HOST}

 

 

No Operation

 

 

 

 

 

 

Empty own tags

[Documentation]

This test has tags

req-42

 

[Tags]

 

 

 

No Operation

 

 

 

 

 

 

Set Tags and Remove Tags Keywords

[Documentation]

This test has tags

mytag, owner-john

 

Set Tags

mytag

 

 

Remove Tags

smoke

req-*

 

     测试配置和拆卸

 

Setting

Value

Value

Value

Test Setup

Open Application

App A

 

Test Teardown

Close Application

 

 

 

Test Case

Action

Argument

Argument

Default values

[Documentation]

Setup and teardown

from setting table

 

Do Something

 

 

 

 

 

 

Overridden setup

[Documentation]

Own setup, teardown

from setting table

 

[Setup]

Open Application

App B

 

Do Something

 

 

 

 

 

 

No teardown

[Documentation]

Default setup, no

teardown at all

 

Do Something

 

 

 

[Teardown]

 

 

 

 

 

 

Using variables

[Documentation]

Setup and teardown

given as variables

 

[Setup]

${SETUP}

 

 

Do Something

 

 

 

[Teardown]

${TEARDOWN}

 

 

Setup and teardown synonyms

Test Setup

Test Precondition

Test Teardown

Test Postcondition

[Setup]

[Precondition]

[Teardown]

[Postcondition]

 

§2.3 创建测试suites

     测试用例文件

Documentation

Used for specifying a test suite documentation

Meta:

Used for setting free test suite metadata.

Suite Setup, Suite Teardown

Specify suite setup and teardown. Have also synonyms Suite Precondition and Suite Postcondition, respectively.

 

     测试用例目录

注意下划线和点号开头的文件被忽略。

初始化文件:__init__.extension

 

     Test suite 名字和文档

Test suite documentation example

Setting

Value

Value

Value

Documentation

An example test suite

documentation with

*some* _formatting_.

...

See test documentation

for more documentation

examples.

 

     免费Test suite元数据

Setting

Value

Value

Value

Meta: Version

2.0

 

 

Meta: More Info

For more information

about *Robot Framework*

see

Meta: Executed At

${HOST}

 

 

 

     suite配置和拆卸

Suite Precondition and Suite Postcondition,

 

§2.4 使用测试库

     使用测试库

导入库

Importing test libraries

Setting

Value

Value

Value

Library

OperatingSystem

 

 

Library

com.company.TestLib

 

 

Library

MyLibrary

arg1

arg2

Library

${LIBRARY}

 

 

 

 

导入库关键字:

Test Case

Action

Argument

Argument

Argument

Example

Do Something

 

 

 

 

Import Library

MyLibrary

arg1

arg2

 

KW From Mylibrary

 

 

 

 

使用绝对路径导入:

Setting

Value

Value

Value

Library

PythonLib.py

 

 

Library

/absolute/path/JavaLib.java

 

 

Library

relative/path/PythonDirLib/

possible

arguments

Library

${RESOURCES}/Example.class

 

 

 

     设定自定义名字和测试库

 

自定义名字:

Setting

Value

Value

Value

Library

com.company.TestLib

WITH NAME

TestLib

Library

${LIBRARY}

WITH NAME

MyName

使用不同名字导入同一库。

Setting

Value

Value

Value

Value

Value

Library

SomeLibrary

localhost

1234

WITH NAME

LocalLib

Library

SomeLibrary

server.domain

8080

WITH NAME

RemoteLib

 

Test Case

Action

Argument

Argument

My Test

LocalLib.Some Keyword

some arg

second arg

 

RemoteLib.Some Keyword

another arg

whatever

 

LocalLib.Another Keyword

 

 

 

     标准库

 

 

阅读(2888) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~