Skip to content

Test Model Configuration

packageSetup()

packageSetup() — returns any

Available in: test Category: Callback Functions

The packageSetup() function is a callback in Wheels’ legacy testing framework. It runs once before the first test case in the test package. Use it to perform setup tasks that are shared across all tests in the package, such as initializing data, creating test records, or configuring environment settings.

component extends="app.tests.Test" {

    function packageSetup() {
        // Run once before any test in this package
        
        // Create a test user
        model("user").new(username="testuser", email="test@example.com").save();

        // Initialize test data
        application.testConfig = {
            siteName: "Wheels Test"
        };
    }

    function test_User_Creation() {
        var user = model("user").findOneByUsername("testuser");
        assert("user eq true");
    }

    function test_Config_Value() {
        assert("application.testConfig.siteName eq 'Wheels Test'");
    }
}