Skip to content

API Reference

Chesko edited this page Oct 9, 2016 · 8 revisions

Extends Quest

API Version: 2

Overview

Papyrus unit test syntax and test runner. Base script for creating and running Lilac unit tests. Must be extended. Generally executed by

 StartQuest MyUnitTestQuest
from the console.

Functions

Functions

describe

Defines and executes a test suite.

Api version added

1

Syntax

bool function describe(string asTestSuiteName, bool abTestCases)

Parameters

  • asTestSuiteName: The name of the test suite.

  • abTestCases: A function that implements this suite's test cases.

Examples

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

bool function myTestSuite()
    it("should test something", myTestCase())

    ; return required by compiler - has no function
    return true
endFunction

Notes

  • Your test suite and case functions must return a boolean value (as shown in the example), or the Fallout 4 compiler will fail. The value doesn't matter. This is due to stricter typing requirements in Fallout 4's Papyrus compiler compared to Skyrim's.

it

Defines and executes a test case (spec).

Api version added

1

Syntax

bool function it(string asTestCaseName, bool abTestSteps)

Parameters

  • asTestCaseName: The name of the test case.

  • abTestSteps: A function that implements this suite's test steps.

Examples

bool function myTestSuite()
    it("should test something", myTestCase())

    ; return required by compiler - has no function
    return true
endFunction

bool function myTestCase()
    expect(true, to, beEqualTo, true)

    ; return required by compiler - has no function
    return true
endFunction

Notes

  • Your test suite and case functions must return a boolean value (as shown in the example), or the Fallout 4 compiler will fail. The value doesn't matter. This is due to stricter typing requirements in Fallout 4's Papyrus compiler compared to Skyrim's.

beforeAll

Override this function to run a block of code before any test case runs (including before any beforeEach).

Api version added

1

Syntax

function beforeAll()

Parameters

None

Examples

;Make sure the quest isn't running and is on stage 12 before any test runs.
function beforeAll()
        TheQuest.Stop()
        TheQuest.SetStage(12)
endFunction

afterAll

Override this function to run a block of code after all test cases run (including after any afterEach).

Api version added

1

Syntax

function afterAll()

Parameters

None

Examples

;Make sure the quest isn't running and is on stage 12 after all tests are run.
function afterAll()
        TheQuest.Stop()
        TheQuest.SetStage(12)
endFunction

beforeEach

Override this function to run a block of code before each test case.

Api version added

1

Syntax

function beforeEach()

Parameters

None

Examples

;Make sure the storm trooper is reset before every test.
function beforeEach()
        stormtrooper.Reset()
endFunction

afterEach

Override this function to run a block of code after each test case.

Api version added

1

Syntax

function afterEach()

Parameters

None

Examples

;Make sure the star destroyer is deleted after every test.
function afterEach()
        destroyer.Disable()
        destroyer.Delete()
endFunction

expect

Defines a new expectation, comparing actual and expected values of any supported type.

Api version added

1 (Fallout 4 only)

Syntax

function expect(var akActual, bool abCondition, int aiMatcher, var akExpected = None)

Parameters

  • akActual: The value under test.

  • abCondition: The condition (to or notTo).

  • aiMatcher: The matcher. See Notes for a list of valid matchers for this expectation.

  • akExpected: The expected value.

Examples

expect(MyArmor, to, beEqualTo, PowerArmor)
expect(5, to, beEqualTo, 5)
expect(5, notTo, beEqualTo, 1.4)
expect(True, to, beTruthy)
expect(0, to, beFalsy)
expect("Preston", to, beEqualTo, "Preston")

Notes

This is a type-independent version of the individual expect* functions and can be used in place of them.

You must use a valid matcher for the type of Actual and Expected. For instance, you cannot check if a Form is "less than" another Form.

The Actual and Expected must be of the exact same supported type (Form, ObjectReference, Int, Float, Bool, or String).

Using 'beTruthy', 'beFalsy', or 'beNone' matcher and not supplying akExpected can produce a (harmless) Papyrus error (warning: Passing NONE to non-object argument 4). If this becomes an issue, use 'to beEqualTo true', or similar, instead.

Valid matchers for this expectation (depending on type):

  • beEqualTo

  • beLessThan

  • beLessThanOrEqualTo

  • beGreaterThan

  • beGreaterThanOrEqualTo

  • beTruthy

  • beFalsy

  • beNone


expectForm

Defines a new expectation, comparing actual and expected Forms.

Api version added

1

Syntax

function expectForm(Form akActual, bool abCondition, int aiMatcher, Form akExpected = None)

Parameters

  • akActual: The form under test.

  • abCondition: The condition (to or notTo).

  • aiMatcher: The matcher. See Notes for a list of valid matchers for this expectation.

  • akExpected: The expected value.

Examples

expectForm(MyArmor, to, beEqualTo, PowerArmor)

Notes

Valid matchers for this expectation:

  • beEqualTo

  • beTruthy

  • beFalsy

  • beNone


expectRef

Defines a new expectation, comparing actual and expected ObjectReferences.

Api version added

1

Syntax

function expectRef(ObjectReference akActual, bool abCondition, int aiMatcher, ObjectReference akExpected = None)

Parameters

  • akActual: The reference under test.

  • abCondition: The condition (to or notTo).

  • aiMatcher: The matcher. See Notes for a list of valid matchers for this expectation.

  • akExpected: The expected value.

Examples

expectRef(FalmerRef, to, beEqualTo, BossFalmerRef)

Notes

Valid matchers for this expectation:

  • beEqualTo

  • beTruthy

  • beFalsy

  • beNone


expectInt

Defines a new expectation, comparing actual and expected integers.

Api version added

1

Syntax

function expectInt(int aiActual, bool abCondition, int aiMatcher, int aiExpected = -1)

Parameters

  • akActual: The integer under test.

  • abCondition: The condition (to or notTo).

  • aiMatcher: The matcher. See Notes for a list of valid matchers for this expectation.

  • akExpected: The expected value.

Examples

expectInt(counter, to, beLessThan, 40)

Notes

Valid matchers for this expectation:

  • beEqualTo

  • beLessThan

  • beGreaterThan

  • beLessThanOrEqualTo

  • beGreaterThanOrEqualTo

  • beTruthy

  • beFalsy


expectFloat

Defines a new expectation, comparing actual and expected floats.

Api version added

1

Syntax

function expectFloat(float afActual, bool abCondition, int aiMatcher, float afExpected = -1.0)

Parameters

  • akActual: The float under test.

  • abCondition: The condition (to or notTo).

  • aiMatcher: The matcher. See Notes for a list of valid matchers for this expectation.

  • akExpected: The expected value.

Examples

expectFloat(GameHour.GetValue(), to, beGreaterThan, 19.0)

Notes

Valid matchers for this expectation:

  • beEqualTo

  • beLessThan

  • beGreaterThan

  • beLessThanOrEqualTo

  • beGreaterThanOrEqualTo

  • beTruthy

  • beFalsy


expectBool

Defines a new expectation, comparing actual and expected booleans.

Api version added

1

Syntax

function expectBool(bool abActual, bool abCondition, int aiMatcher, bool abExpected = false)

Parameters

  • akActual: The boolean under test.

  • abCondition: The condition (to or notTo).

  • aiMatcher: The matcher. See Notes for a list of valid matchers for this expectation.

  • akExpected: The expected value.

Examples

expectBool(Follower.IsEssential(), to, beTruthy)

Notes

Valid matchers for this expectation:

  • beEqualTo

  • beTruthy

  • beFalsy


expectString

Defines a new expectation, comparing actual and expected strings.

Api version added

1

Syntax

function expectString(string asActual, bool abCondition, int aiMatcher, string asExpected = "")

Parameters

  • akActual: The string under test.

  • abCondition: The condition (to or notTo).

  • aiMatcher: The matcher. See Notes for a list of valid matchers for this expectation.

  • akExpected: The expected value.

Examples

expectString("Preston", to, beEqualTo, "Preston")

Notes

Valid matchers for this expectation:

  • beEqualTo

  • beTruthy

  • beFalsy

Clone this wiki locally