加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

前天把以前同事介绍的敏捷开发的书看完了,决定开始单元测试驱动

发布时间:2020-12-13 23:12:27 所属栏目:百科 来源:网络整理
导读:ios开发的单元测试简单一些 unity的没用过,今天搜索了下,发现居然有官方工具,更新到1.22版 决定使用官方的 地址是:unit test tool 用法和注意事项 两种单元测试: A.NUnit,官网:http://www.nunit.org: 发现一篇好文章http://confach.cnblogs.com/archive/2005

ios开发的单元测试简单一些

unity的没用过,今天搜索了下,发现居然有官方工具,更新到1.22版

决定使用官方的

地址是:unit test tool


用法和注意事项


两种单元测试:

A.NUnit,官网:http://www.nunit.org:

发现一篇好文章http://confach.cnblogs.com/archive/2005/06/20/177817.aspx将NUnit的

测试静态类的(未继承MONOBehavior)

跟ios开发的xctest差不多,用attritube:[Test]表明下面的方法是个测试,命名空间是Nunit.frameword

Assert.~~~~断言~~,巴拉巴拉的什么表明测试通过没有

Assert.Pass();

ssert.Fail();

还有什么比较之类的方法

AreEqual相等

AreNotEual不相等

Greater大于

Less小于

IsNotNull不为空

.等等等还有好多不明白干什么的断言方法,具体列表在下面的源文件里面,请自行浏览猜测用途




第二种是Integration Test

就是可以在运行时做的单元测试



具体流程是

1.打开窗口

2.建立测试

3.设置是否断言组件(Assertions组件)通过就pass(通过任意一个之后貌似就会认为是成功了,而不是timeOut或者继续其他断言判断,也就是说后面如果有失败的就不继续测了,建议关闭)

4.设置超时时间,超过之后视为通过

5.在子物体中添加测试物体添加脚本(Assertion默认有:float,bool,vector2,3,4,renderer等判断)

6.添加断言脚本或自己写测试脚本


PS:默认的几个断言类型如果觉得不够,自己写,继承泛型类ComparerBaseGeneric<T1,T2>,重写Compare方法即可,ComparerBaseGeneric<T>则是需要一个参数的版本


当自己写单元测试脚本,

通过或失败时执行IntegrationTest.Pass (gameObject);或IntegrationTest.Fail (gameObject);即可,这个脚本需要继承Monobehavior,挂载到物体上

用上了单元测试驱动开发,顿时感觉自己对代码的信心加强了不少啊





usingNUnit.FrameworkConstraints;
SystemCollectionsComponentModelnamespaceFramework
{
publicclassAssert
//
//StaticProperties
staticintCounter
get
result=Assertcounter;
=0return}
}

Constructors
protected()
Methods
[CLSCompliant(false)]
voidAreEqualuintexpected,actual)
That(IsEqualTo),164)">null);
stringmessageparamsobject[]argsulonglongdouble?deltaAssertDoublesAreEqualget_Value(),164)">decimalAreNotEqualNotfloatAreNotSameSameAsAreSameifIsNaN)||IsInfinity))
).WithinByValIResolveConstraintexpressionExceptionCatchTypeexpectedExceptionTypeTestDelegatecodeThrows(newInstanceOfTypeConstrainttypeof)),68)">T<>()where:Exception
)(()));
ContainsICollectionCollectionContainsConstraintDoesNotThrowThrowsNothingConstraintEmptyEditorBrowsableEditorBrowsableStateNeverboolEqualsabthrowAssertionException("Assert.EqualsshouldnotbeusedforAssertions"Fail===else
!=&&Length>FormatFalseconditionGreaterarg1arg2GreaterThanIComparableGreaterOrEqualGreaterThanOrEqualToIgnoreIgnoreExceptionInconclusiveInconclusiveExceptionIsAssignableFrom>(AssignableFromIsEmptyaStringEmptyStringConstraintIEnumerablecollectionEmptyCollectionConstraintIsFalseIsInstanceOfInstanceOfObsolete]
IsInstanceOfTypeaDoubleNaNIsNotAssignableFromIsNotEmptyIsNotInstanceOfIsNotInstanceOfTypeIsNotNullanObjectNullIsNotNullOrEmptyNotConstraintNullOrEmptyStringConstraint()),68)">IsNullIsNullOrEmptyIsTrueTrueLessLessThanLessOrEqualLessThanOrEqualToNotNullPassSuccessExceptionReferenceEqualsAssert.ReferenceEqualsshouldnotbeusedforAssertionsActualValueDelegatedelexprConstraintconstraintResolve();
IncrementAssertCount(!MatchesMessageWritermessageWriter=TextMessageWriterWriteMessageToToString());
>(refExceptionTypeConstraintextry
catchex2}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读