GithubHelp home page GithubHelp logo

unittest's Introduction

UnitTest

UnitTest

1. 单元测试的目的是为了测试数据合法性
eg:
    创建一个数据模型,属性 age name
    age 数据区间 0~120;
    name 不能为空,
    
2. 引入模型类头文件到UnitTest文件
3. 创建一个test 开头的函数用于测试
4. 在test 函数中用XCTAssert 测试数据合法性
eg:
    XCTAssert(obj.name != nil, @"姓名为空");
    如果 obj.name 数据为空,会报错 到这一行,说明有一个输入源数据name 为空,向上查找即可
    XCTAssert(obj.age > 0 && obj.age < 130, @"年龄超限");
    如果输入源的age 131 那么断言 就会报错 年龄超限 如果 断言为true 那么不报错

5. 点击刚才创建的test开头函数的左边有一个run按钮开始测试


XCTAssert 想当于 XCTAssertTrue  如果条件为!那么报错
XCTAssertFalse 相反 如果条件为! 不报错 否则报错
XCTAssertNotNil 条件不能为NIl 不报错,否则报错

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.