Robotframework自动化6-基础关键字介绍(3)

前言

这一章节介绍一下断言时用到的关键字,断言是写测试用例的必备,没有断言的测试用例是没有灵魂的。

一:Should Be Equal 

       Should Be Equal 是用来判断实践结果和预期结果是否一致。比如:设置一个变量${a}=1,然后断言${a}与1是否相等。

      

 此时运行结果肯定是通过的,如果将变量${a}与2进行比较,则结果是肯定是不通过的。

       

1 Starting test: Testcase.测试套件.关键字介绍3
2 20191224 17:01:55.110 : INFO : ${a} = 1
3 20191224 17:01:55.112 : FAIL : 1 != 2
4 Ending test: Testcase.测试套件.关键字介绍3

二.Should Be True

    Should Be True 是用来断言返回结果是否为True,设置变量${a}=1.然后断言${a}与2如果相等就是返回true,则断言成功,如果返回false就是断言失败。

      

1 Starting test: Testcase.测试套件.关键字介绍3
2 20191224 17:28:01.897 : INFO : ${a} = 1
3 20191224 17:28:01.898 : FAIL : 断言失败
4 Ending test: Testcase.测试套件.关键字介绍3

三 .Should Contain 

Should Contain  是用来断言某个字符串中是否包含了某一字符串,模糊匹配

helloworld字符串中肯定不包含apple字符,所以会断言失败,如果将apple换成hello则会成功

      

1 Starting test: Testcase.测试套件.关键字介绍3
2 20191224 17:43:07.227 : INFO : ${a} = helloworld
3 20191224 17:43:07.228 : FAIL : 'helloworld' does not contain 'apple'
4 Ending test: Testcase.测试套件.关键字介绍3

四.Should End With 

 Should End With 是指某一字符串的结束部分是不是以我们指定的字符进行结束。

同样的helloworld不是以apple字符结束的,如果将apple换成world则会成功。

      

1 Starting test: Testcase.测试套件.关键字介绍3
2 20191224 17:48:44.311 : INFO : ${a} = helloworld
3 20191224 17:48:44.312 : FAIL : 'helloworld' does not end with 'apple'
4 Ending test: Testcase.测试套件.关键字介绍3

五:其他断言关键字

      

       

此图来源:Robot Framework 自动化测试框架核心指南

关注个人公众号:测试开发进阶之路

原文地址:https://www.cnblogs.com/zengxuejie/p/12085088.html