• [翻译]NUnitString && Collection Assert (七)


    [翻译]NUnit---String && Collection Assert (七)

    2013-04-13 21:31 by Max蚊子, 207 阅读, 0 评论, 收藏编辑

    StringAssert (NUnit 2.2.3)

    StringAssert类提供一系列检查字符串的方法。

    View Code
    StringAssert.Contains( string expected, string actual );
    StringAssert.Contains( string expected, string actual, 
                    string message );
    StringAssert.Contains( string expected, string actual,
                    string message, params object[] args );
    
    StringAssert.StartsWith( string expected, string actual );
    StringAssert.StartsWith( string expected, string actual, 
                    string message );
    StringAssert.StartsWith( string expected, string actual,
                    string message, params object[] args );
    
    StringAssert.EndsWith( string expected, string actual );
    StringAssert.EndsWith( string expected, string actual, 
                    string message );
    StringAssert.EndsWith( string expected, string actual,
                    string message, params object[] args );
    
    StringAssert.AreEqualIgnoringCase( string expected, string actual );
    StringAssert.AreEqualIgnoringCase( string expected, string actual, 
                    string message );
    StringAssert.AreEqualIgnoringCase( string expected, string actual,
                    string message params object[] args );
                    
    StringAssert.IsMatch( string regexPattern, string actual );
    StringAssert.IsMatch( string regexPattern, string actual, 
                    string message );
    StringAssert.IsMatch( string regexPattern, string actual,
                    string message, params object[] args );

    CollectionAssert (NUnit 2.4 / 2.5)

    CollectionAssert类提供一系列检查两个集合及内容的方法。AreEqual检查两个集合对应元素都相等时则集合相等。AreEquivalent不按照舒顺序检查两个集合内容是否相等。这两种情况都是使用NUnit默认相等比较。

    从NUnit2.4.6开始,这些方法都用于实现了IEnumerable接口的对象。2.4.6以前的版本仅支持集合对象。

    View Code
    CollectionAssert.AllItemsAreInstancesOfType( IEnumerable collection,
              Type expectedType );
    CollectionAssert.AllItemsAreInstancesOfType( IEnumerable collection,
              Type expectedType, string message );
    CollectionAssert.AllItemsAreInstancesOfType( IEnumerable collection,
              Type expectedType, string message, params object[] args );
    
    CollectionAssert.AllItemsAreNotNull( IEnumerable collection );
    CollectionAssert.AllItemsAreNotNull( IEnumerable collection,
              string message );
    CollectionAssert.AllItemsAreNotNull( IEnumerable collection,
              string message, params object[] args );
    
    CollectionAssert.AllItemsAreUnique( IEnumerable collection );
    CollectionAssert.AllItemsAreUnique( IEnumerable collection,
              string message );
    CollectionAssert.AllItemsAreUnique( IEnumerable collection,
              string message, params object[] args );
    
    CollectionAssert.AreEqual( IEnumerable expected, IEnumerable actual );
    CollectionAssert.AreEqual( IEnumerable expected, IEnumerable actual,
              string message );
    CollectionAssert.AreEqual( IEnumerable expected, IEnumerable actual
              string message, params object[] args );
    
    CollectionAssert.AreEquivalent( IEnumerable expected, IEnumerable actual);
    CollectionAssert.AreEquivalent( IEnumerable expected, IEnumerable actual,
              string message );
    CollectionAssert.AreEquivalent( IEnumerable expected, IEnumerable actual
              string message, params object[] args );
    
    CollectionAssert.AreNotEqual( IEnumerable expected, IEnumerable actual );
    CollectionAssert.AreNotEqual( IEnumerable expected, IEnumerable actual,
              string message );
    CollectionAssert.AreNotEqual( IEnumerableon expected, IEnumerable actual
              string message, params object[] args );
    
    CollectionAssert.AreNotEquivalent( IEnumerable expected,
              IEnumerable actual );
    CollectionAssert.AreNotEquivalent( IEnumerable expected,
              IEnumerable actual, string message );
    CollectionAssert.AreNotEquivalent( IEnumerable expected,
              IEnumerable actual, string message, params object[] args );
    
    CollectionAssert.Contains( IEnumerable expected, object actual );
    CollectionAssert.Contains( IEnumerable expected, object actual,
              string message );
    CollectionAssert.Contains( IEnumerable expected, object actual
              string message, params object[] args );
    
    CollectionAssert.DoesNotContain( IEnumerable expected, object actual );
    CollectionAssert.DoesNotContain( IEnumerable expected, object actual,
              string message );
    CollectionAssert.DoesNotContain( IEnumerable expected, object actual
              string message, params object[] args );
    
    CollectionAssert.IsSubsetOf( IEnumerable subset, IEnumerable superset );
    CollectionAssert.IsSubsetOf( IEnumerable subset, IEnumerable superset,
              string message );
    CollectionAssert.IsSubsetOf( IEnumerable subset, IEnumerable superset,
              string message, params object[] args );
    
    CollectionAssert.IsNotSubsetOf( IEnumerable subset, IEnumerable superset);
    CollectionAssert.IsNotSubsetOf( IEnumerable subset, IEnumerable superset,
              string message );
    CollectionAssert.IsNotSubsetOf( IEnumerable subset, IEnumerable superset,
              string message, params object[] args );
    
    CollectionAssert.IsEmpty( IEnumerable collection );
    CollectionAssert.IsEmpty( IEnumerable collection, string message );
    CollectionAssert.IsEmpty( IEnumerable collection, string message,
              params object[] args );
    
    CollectionAssert.IsNotEmpty( IEnumerable collection );
    CollectionAssert.IsNotEmpty( IEnumerable collection, string message );
    CollectionAssert.IsNotEmpty( IEnumerable collection, string message,
              params object[] args );

    从NUnit2.5开始,可以使用以下方法:

    View Code
    CollectionAssert.IsOrdered( IEnumerable collection ); CollectionAssert.IsOrdered( IEnumerable collection, string message ); CollectionAssert.IsOrdered( IEnumerable collection, string message,params object[] args ); CollectionAssert.IsOrdered( IEnumerable collection, IComparer comparer ); CollectionAssert.IsOrdered( IEnumerable collection, IComparer comparer, string message ); CollectionAssert.IsOrdered( IEnumerable collection, IComparer comparer, string message, paramsobject[] args );

    FileAssert (NUnit 2.4)


    FileAssert类提供了比较两个文件的方法,包括StreamFileInfo、指定文件路径string的参数格式。

    View Code
    FileAssert.AreEqual( Stream expected, Stream actual );
    FileAssert.AreEqual( Stream expected, Stream actual, 
                    string message );
    FileAssert.AreEqual( Stream expected, Stream actual,
                    string message, params object[] args );
    
    FileAssert.AreEqual( FileInfo expected, FileInfo actual );
    FileAssert.AreEqual( FileInfo expected, FileInfo actual, 
                    string message );
    FileAssert.AreEqual( FileInfo expected, FileInfo actual,
                    string message, params object[] args );
    
    FileAssert.AreEqual( string expected, string actual );
    FileAssert.AreEqual( string expected, string actual, 
                    string message );
    FileAssert.AreEqual( string expected, string actual,
                    string message, params object[] args );
    
    FileAssert.AreNotEqual( Stream expected, Stream actual );
    FileAssert.AreNotEqual( Stream expected, Stream actual, 
                    string message );
    FileAssert.AreNotEqual( Stream expected, Stream actual,
                    string message, params object[] args );
    
    FileAssert.AreNotEqual( FileInfo expected, FileInfo actual );
    FileAssert.AreNotEqual( FileInfo expected, FileInfo actual, 
                    string message );
    FileAssert.AreNotEqual( FileInfo expected, FileInfo actual,
                    string message, params object[] args );
    
    FileAssert.AreNotEqual( string expected, string actual );
    FileAssert.AreNotEqual( string expected, string actual, 
                    string message );
    FileAssert.AreNotEqual( string expected, string actual,
                    string message, params object[] args );

    DirectoryAssert (NUnit 2.5)

    DirectoryAssert类提供了一系列方法来比较文件系统目录,DirectoryInfo或者指定目录路径的string格式的参数。

    DirectoryAssert.AreEqual() and DirectoryAssert.AreNotEqual() 比较两个目录是否相等。如果目录有相同的FullName, Attributes, CreationTime and LastAccessTime则认为是相等。

    Note:如果不满足以上条件即使两个不同目录包含相同的文件也不相等

    View Code
    DirectoryAssert.AreEqual( DirectoryInfo expected, DirectoryInfo actual );
    DirectoryAssert.AreEqual( DirectoryInfo expected, DirectoryInfo actual, 
                    string message );
    DirectoryAssert.AreEqual( DirectoryInfo expected, DirectoryInfo actual,
                    string message, params object[] args );
    
    DirectoryAssert.AreEqual( string expected, string actual );
    DirectoryAssert.AreEqual( string expected, string actual, 
                    string message );
    DirectoryAssert.AreEqual( string expected, string actual,
                    string message, params object[] args );
    
    DirectoryAssert.AreNotEqual( DirectoryInfo expected, DirectoryInfo actual );
    DirectoryAssert.AreNotEqual( DirectoryInfo expected, DirectoryInfo actual, 
                    string message );
    DirectoryAssert.AreNotEqual( DirectoryInfo expected, DirectoryInfo actual,
                    string message, params object[] args );
    
    DirectoryAssert.AreNotEqual( string expected, string actual );
    DirectoryAssert.AreNotEqual( string expected, string actual, 
                    string message );
    DirectoryAssert.AreNotEqual( string expected, string actual,
                    string message, params object[] args );

    DirectoryAssert.IsEmpty() and DirectoryAssert.IsNotEmpty() 检测指定的目录是否为empty

    View Code
    DirectoryAssert.IsEmpty( DirectoryInfo directory );
    DirectoryAssert.IsEmpty( DirectoryInfo directory, string message );
    DirectoryAssert.IsEmpty( DirectoryInfo directory,
                    string message, params object[] args );
    
    DirectoryAssert.IsEmpty( string directory );
    DirectoryAssert.IsEmpty( string directory, string message );
    DirectoryAssert.IsEmpty( string directory,
                    string message, params object[] args );
    
    DirectoryAssert.IsNotEmpty( DirectoryInfo directory );
    DirectoryAssert.IsNotEmpty( DirectoryInfo directory, string message );
    DirectoryAssert.IsNotEmpty( DirectoryInfo directory,
                    string message, params object[] args );
    
    DirectoryAssert.IsNotEmpty( string directory );
    DirectoryAssert.IsNotEmpty( string directory, string message );
    DirectoryAssert.IsNotEmpty( string directory,
                    string message, params object[] args );

    DirectoryAssert.IsWithin() and DirectoryAssert.IsNotWithin()检测第二个目录是否是第一个目录的直接或者间接子目录。

    View Code
    DirectoryAssert.IsWithin( DirectoryInfo expected, DirectoryInfo actual );
    DirectoryAssert.IsWithin( DirectoryInfo expected, DirectoryInfo actual,
                    string message );
    DirectoryAssert.IsWithin( DirectoryInfo expected, DirectoryInfo actual,
                    string message, params object[] args );
    
    DirectoryAssert.IsWithin( string expected, string actual );
    DirectoryAssert.IsWithin( string expected, string actual,
                    string message );
    DirectoryAssert.IsWithin( string expected, string actual,
                    string message, params object[] args );
    
    DirectoryAssert.IsNotWithin( DirectoryInfo expected, DirectoryInfo actual );
    DirectoryAssert.IsNotWithin( DirectoryInfo expected, DirectoryInfo actual,
                    string message );
    DirectoryAssert.IsNotWithin( DirectoryInfo expected, DirectoryInfo actual,
                    string message, params object[] args );
    
    DirectoryAssert.IsNotWithin( string expected, string actual );
    DirectoryAssert.IsNotWithin( string expected, string actual,
                    string message );
    DirectoryAssert.IsNotWithin( string expected, string actual,
                    string message, params object[] args );

    随笔分类 -测试相关

    [翻译]NUnit---String && Collection Assert (七)

    2013-04-13 21:31 by Max蚊子, 215 visits, 网摘收藏编辑
    摘要:StringAssert (NUnit 2.2.3)StringAssert类提供一系列检查字符串的方法。View Code StringAssert.Contains( string expected, string actual );StringAssert.Contains( string expected, string actual, string message );StringAssert.Contains( string expected, string actual, string message, params ... 阅读全文

    [翻译]NUnit---Exception && Utility Methods (六)

    2013-04-01 21:55 by Max蚊子, 550 visits, 网摘收藏编辑
    摘要:Exception Asserts (NUnit 2.5)Assert.Throws作用于类本身,而不是比较值,它调用代理来验证抛代码片段出一个特定异常。在一个类可中Assert成功时可以是返回一个Exception而不是void,下面的例子代表了几种使用方式。Assert.Throws可以使用约束参数或者是异常类型作为预期的抛出异常类型。类型格式可以是泛型或者一般类型。Assert.DoesNotThrow用于确认代理不会抛出异常。Assert.Catch与 Assert.Throws 相似,但是当一个异常派生意另一个异常是会通过。View Code Exception Assert.Thr 阅读全文

    [翻译]NUnit---Condition Asserts && Comparisons Asserts && Type Asserts (五)

    2013-03-31 14:06 by Max蚊子, 513 visits, 网摘收藏编辑
    摘要:Condition Asserts测试指定条件的方法称作条件测试,测试结果作为第一个参数,第二个是可选的消息参数。提供了如下方法:View Code Assert.IsTrue( bool condition );Assert.IsTrue( bool condition, string message );Assert.IsTrue( bool condition, string message, object[] parms );Assert.True( bool condition );Assert.True( bool condition, string message );Asser 阅读全文

    [翻译]NUnit---Equality Asserts&& Identity Asserts (四)

    2013-03-31 09:58 by Max蚊子, 541 visits, 网摘收藏编辑
    摘要:Equality Asserts 这些方法测试两个参数是否相等。语言不自动装修的普通类型可以使用对应的重载的方法。View Code Assert.AreEqual( int expected, int actual );Assert.AreEqual( int expected, int actual, string message );Assert.AreEqual( int expected, int actual, string message, params object[] parms ); Assert.AreE... 阅读全文

    [译]NUnit--Installation(三)

    2013-03-29 21:55 by Max蚊子, 477 visits, 网摘收藏编辑
    摘要:InstallationNUnit安装程序默认安装文件路径为C:\ProgramFiles\NUnit2.6.2。根据用户选择安装的选项,安装文件有三个子文件夹:bin、doc、samples。源码以后不再与安装文件一起打包,提供单独下载。Running NUnit根据电脑不同操作系统,在.NET、Mono等的NUnit安装程序在开始菜单有几个快捷方式。尽管可以在独立进程中运行不同CLR版本的测试,对于NUnit2.5,GUI只能在CLR2.0下运行。Installation VerificationNUnit自带的测试作为安装选项,如果你安装了,你可以通过运行NUnit GUI加载并运行NU 阅读全文

    [翻译]NUnit--Getting Started(二)

    2013-03-25 22:08 by Max蚊子, 776 visits, 网摘收藏编辑
    摘要:Getting Started with NUnit如果你打算开始学习,到下载页面选择一个NUnit版本。安装页面包含了安装说明。开始NUnit阅读Quick Start页面。验证了一个C#银行应用程序的开发过程。查看Samples部分例子,包括了VB.NET、J#以及托管C++。使用哪种形式? NUnit有两种不同方式来测试用例。 A.控制台:NUnit-Console.exe,可以最快的使用,但是不能进行交互。 B.GUI:NUnit.exe,是一个Windows窗体应用程序提供可视化的界面,同时能够可选择性是运行测试。NUnit Quick StartNote:本页面是基于... 阅读全文

    [翻译]NUnit--前言(一)

    2013-03-24 22:35 by Max蚊子, 721 visits, 网摘收藏编辑
    摘要:前言: 翻译这个系列主要是自己在学习NUnit之时看英文文档大部分能看懂但是有些还是功底不足,所以在方便自己以后再学习的时候可以快速查找,也能够加深印象以及掌握的更好。同时在搜索网上关于NUnit系列文章,发现基本都不是最新的系列,由于新版本与老版本有些学出入,发到首页可以方便大家一起学习。 再能力有限,如果有翻译错误请园友指正,笔者一定努力修正。正题: NUnit官网为http://www.nunit.org 进入官网点击Documentation就可以查看在线文档。 目前NUnit最新版本为2.6.2 翻译网页:http://www.nunit.org/index.php?p... 阅读全文

    [测试]单元测试框架NUnit

    2013-02-17 14:19 by Max蚊子, 1172 visits, 网摘收藏编辑
    摘要:说到测试,相信大家都或多或少了解。按照各自分类,就自己知道包括 A.单元测试、集成测试、系统测试 B.白盒测试、黑盒测试 C.压力测试、性能测试、安全测试 ...... 反正是太多太多。就做开发以来,就只有自测和交叉测试,基本都是按照需求测试是否实现了相关的业务和什么提示信息、文本长度等细节问题,如果有专门测试人员撰写的用例就也跑一次,然后就是乱点看看有什么异常,然后就交给测试人员测试。 基本都是业务逻辑测试,没有做过单元测试。为了在经济或在技术上进行突破,所以在努力学习各种技术。查看智联招聘上看的招聘信息和阅读园子里面的前辈的文章显示,要想有提升还得懂单元测试才行。 最开始... 阅读全文
    ※如果你觉得这篇文章不错,请点击推荐。如果你觉得我写的对你有用请关注我。
    作者:Max蚊子
    出处:http://www.cnblogs.com/kim01/ 
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
     
    分类: 测试相关翻译
  • 相关阅读:
    python自动化测试框架的unittest与pytest前后置条件的区别
    XPTH定位总结
    自动化用例设计原则
    python 自动化测试框架unittest与pytest的区别
    Appium工作原理
    Fiddler抓包过滤
    monkey介绍及常用命令
    怎样安装python的 模块、 包、 库方法总结
    安装uiautomator2 + python 自动化环境
    APP自动化,怎样让应用不重置?
  • 原文地址:https://www.cnblogs.com/Leo_wl/p/3020400.html
Copyright © 2020-2023  润新知