ASUnit

Author:
Nir Soffer, Lifepillar
Version:
1.2.4

Introduction

License: GNU GPL, see COPYING for details.

Discussion

An AppleScript testing framework.



Classes

ASUnitSentinel

Sentinel object used to mark missing values.

ConsoleLogger

Displays test results in the console.

Observer

Base class for observers.

ScriptEditorLogger

Displays test results in a new AppleScript Editor document.

StdoutLogger

Prints colorful test results to the standard output.

TestCase

Models a certain configuration of the system being tested.

TestComponent

The base class for test components.

TestLogger

Base class for loggers.

Visitor

Base class for visitors.



Functions

autorun

Automatically runs all the registered tests.

makeAssertions

Factory handler to generate a test script.

makeFixture

Creates an unregistered fixture inheriting from TestCase.

makeTestCase

Creates an unregistered TestCase inheriting from the current fixture.

makeTestLoader

Loads tests from files and folders, and returns a suite with all tests.

makeTestResult

Builds and returns a TestResult object.

makeTestSuite

Creates a test suite.

registerFixture

Convenience handler for registering fixture inheriting from TestCase.

registerFixtureOfKind

Primitive registration handler.

registerTestCase

Creates a test case and registers it with the main script suite.

TestSet

A more user-friendly name for registerFixture().

UnitTest

A more user-friendly name for registerTestCase().


autorun


Automatically runs all the registered tests.

on autorun(
    aTestSuite)

makeAssertions


Factory handler to generate a test script.

on makeAssertions(
    theParent)
Parameters
theParent

[script] The script to inherit from.

Embedded Classes
Return Value

A script inheriting from the given script and implementing assertions.

Discussion

This handler is used to create a script that inherits from theParent and implements testing assertions.


makeFixture


Creates an unregistered fixture inheriting from TestCase.

Discussion

A user test case inherits from the user fixture, which inherit from TestCase. Test cases are automatically registered while compiling a script, using two simple rules:

  1. Each fixture should call registerFixture() to register the fixture and set its parent to TestCase.

  2. Each tests case should call registerTestCase() to register the test case and set its parent to the current fixture.

To create a fixture inheriting from a user defined TestCase, create a script inheriting from TestCase, then create the concrete fixture script inheriting from your custom TestCase script:

		script |user defined TestCase|
			property parent: makeFixture()
			-- define your custom handlers here
		end
		
		script |concrete fixture|
			property parent: registerFixtureOfKind(me, |user defined TestCase|)
			-- define your test cases here
		end
		

makeTestCase


Creates an unregistered TestCase inheriting from the current fixture.

Discussion

You can run the test case or add it manually to a suite. This feature is essential for ASUnit own unit tests.


makeTestLoader


Loads tests from files and folders, and returns a suite with all tests.


makeTestResult


Builds and returns a TestResult object.

on makeTestResult(
    aName)
Embedded Classes

makeTestSuite


Creates a test suite.

on makeTestSuite(
    aName)
Embedded Classes
Discussion

Each test script should define a suite property to support automatic registration of test cases. If a suite is not defined, tests will have to be registered with a suite manually. You may define your own suite class, inheriting from TestSuite. Each test script should define a suite property and initialize it with makeTestSuite(), or with a TestSuite subclass.


registerFixture


Convenience handler for registering fixture inheriting from TestCase.

on registerFixture(
    aUserFixture)

registerFixtureOfKind


Primitive registration handler.

on registerFixtureOfKind(
    aUserFixture,
    aParent)
Discussion

May be used to register a fixture inheriting from a TestCase subclass.


registerTestCase


Creates a test case and registers it with the main script suite.

on registerTestCase(
    aUserTestCase)
Discussion

This test will run automatically when you run the suite.


TestSet


A more user-friendly name for registerFixture().

on TestSet(
    aUserFixture)

UnitTest


A more user-friendly name for registerTestCase().

on UnitTest(
    aUserTestCase)

Globals

_currentFixture

[script] Saves the current fixture while compiling test cases in a fixture.

id

[text] ASUnit's id.

name

[text] ASUnit's name.

suite

Used to automatically collect tests in a script file.

TEST_FAILED

Error number signalling a failed test.

TEST_SKIPPED

Error number signalling a skipped test.

TEST_SUCCEEDED_BUT_SHOULD_HAVE_FAILED

Error number used inside failIf().

TOP_LEVEL

A property that refers to the top-level script.

version

[text] ASUnit's version.


_currentFixture


[script] Saves the current fixture while compiling test cases in a fixture.

property _currentFixture : missing value 

id


[text] ASUnit's id.

property id : "com.lifepillar.ASUnit" 

name


[text] ASUnit's name.

property name : "ASUnit" 

suite


Used to automatically collect tests in a script file.

property suite : ASUnitSentinel 
Discussion

If a test script defines its own suite property, this property will be shadowed.


TEST_FAILED


Error number signalling a failed test.

property TEST_FAILED : 1000 

TEST_SKIPPED


Error number signalling a skipped test.

property TEST_SKIPPED : 1001 

TEST_SUCCEEDED_BUT_SHOULD_HAVE_FAILED


Error number used inside failIf().


TOP_LEVEL


A property that refers to the top-level script.

property TOP_LEVEL : me 

version


[text] ASUnit's version.

property version : "1.2.4"