Skip to content

1. Getting Started

Chesko edited this page Sep 15, 2016 · 16 revisions

Install

All of Lilac is contained in a single script file: Lilac.psc. Just download Lilac and install it using a mod manager, or, drop Lilac.psc into your Scripts/Source folder.

The optional LilacTestLilac package contains Lilac as well as Lilac's own unit tests for itself. (Yes, Lilac can test itself.) You can run them by loading LilacTestLilac.esp, opening the console, and entering startquest LilacTests.

Compiling and running Lilac tests requires SKSE 1.7.3+. Your mod's requirements will not change, because you, the mod developer, will probably be the only one running these tests.

Hello Lilac

Lilac test scripts are attached to quests. Start your script by extending Lilac.

scriptname MyTestScript extends Lilac

Suites describe Your Tests

A test suite starts off with a call to the Lilac function describe, which has two parameters: a string and a function. The string is a name or title for a test suite – usually what is under test. The function is a block of code that implements the suite.

All of your describe calls must exist in a special Lilac function called TestSuites. TestSuites is a "magic function" that you must declare as shown below and is called for you automatically when your test script is run, you don't have to call it yourself.

function TestSuites()
    describe("A suite", myTestSuite())
endFunction

Specs Are What it Should Do

Test cases (or "specs") are defined by calling the Lilac function it, which, like describe, takes a string and a function. The string is a title for the test case and the function is the test itself. A test case contains one or more expectations of the code under test.

An expectation in Lilac is an assertion that can be either true or false. A test case with all true expectations is a passing spec. A test case with one or more expectations that evaluate to false is a failing spec.

function myTestSuite()
    it("contains spec with an expectation", myTestCase())
endFunction

function myTestCase()
    expectBool(True, to, beEqualTo, True)
endFunction

It’s Just Functions

Since describe and it are just functions that call other functions, they can contain any code necessary to implement the test.

function TestSuites()
    describe("A suite is just a function", suite())
endFunction

function suite()
    it("and so is a spec", spec())
endFunction

function spec()
    bool a = True
    expectBool(a, to, beEqualTo, True)
endFunction

Clone this wiki locally