Coder Social home page Coder Social logo

nsunit's Introduction

NSUnit

NSUnit is a unit testing framework for Objective-C projects. NSUnit builds on top of SenTestingKit and provides a more Objective-C friendly API, particularly for testing against Foundation classes.

The Assert Class

The Assert class is the main test entry point to NSUnit. Tests are generally in the form:

 [Assert that:<subject> <verb>:<condition>]

Some examples:

 [Assert that:name isNot:[AnEmpty string]];
 [Assert that:name isNot:[Equal to:@"Omar"]];
 [Assert that:name is:[Equal to:"McNulty"]];
 [Assert that:someArrayOfInts areAll:[Less than:@20]];

Handling primitives with the The article

Primitive types such as doubles and ints can be automatically converted to their appropriate NSObject type using the The article.

Some examples:

 [Assert that:[The int:i] is:[Equal to:@25]];
 [Assert that:[The double:d] is:[Less than:@10]];

Ensuring Failure

NSUnit's Assert class provides a method for ensuring test failures. The fails:(void (^)(void)) method ensures that the supplied block raises an exception. For example

[Assert fails:^{
    [WebService connectToUrl:nil];
}];

Verbs

The following verbs are available:

is - The condition evaluates to true.
isNot - The condition evaluates to false.
areAll - Each value in the provided collection evaluates to true.
areAllNot - Each value in the provided collection evaluates to false.

Conditions

The following conditions are available:

Equal to: - The subject equals the provided value.

TheSame as: - The subject is the exact same object as the provided value.

Less than: - The subject is less than the provided value. Both values must be non-nil numbers.
Less thanOrEqual: - The subject is less than or equal to the provided value. Both values must be non-nil numbers.

Greater than: - The subject is greater than the provided value. Both values must be non-nil numbers.
Greater thanOrEqual: - The subject is greater than or equal to the provided value. Both values must be non-nil numbers.

Between low: and: - The subject is a number between the two provided values, inclusive. All values must be non-nil numbers.

AnEmpty array: - The subject is an empty array.
AnEmpty string: - The subject is an empty string.

More examples can be found in NSUnit's unit tests.

Building

NSUnit is built using the iOS Univeral Framework

nsunit's People

Contributors

jacksonh avatar

Watchers

Nathaniel Bomberger avatar James Cloos avatar

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.