← ClaudeAtlas

coldbox-testing-modellisted

Use this skill when unit testing ColdBox model objects (services, repositories, entities, or utility classes) in isolation using BaseModelTest, accessing the pre-wired model variable, leveraging the built-in mock helpers (mockLogger, mockLogBox, mockCacheBox, mockWireBox), calling model.init() to initialize the component, mocking injected properties with prepareMock(), or scaffolding model tests with CommandBox.
ColdBox/skills · ★ 0 · Testing & QA · score 61
Install: claude install-skill ColdBox/skills
# Model / Service Unit Testing in ColdBox ## When to Use This Skill - Unit testing a service, repository, ORM entity, or utility model in complete isolation - Mocking logger, LogBox, CacheBox, or WireBox dependencies pre-wired by ColdBox - Testing model logic without loading the full ColdBox virtual app - Injecting MockBox stubs for model's injected properties --- ## Base Class ```boxlang coldbox.system.testing.BaseModelTest ``` Extends `BaseTestCase` with `loadColdBox="false"` — no virtual app is started. Your model CFC is instantiated and handed to you in `variables.model`. --- ## Minimal Setup ```boxlang class extends="coldbox.system.testing.BaseModelTest" model="models.UserService" { function beforeAll() { super.setup() // creates variables.model and pre-wired mocks model.init() // call your component's own init() if needed } function run() { describe( "UserService", () => { it( "returns an empty array by default", () => { expect( model.findAll() ).toBeArray() } ) } ) } } ``` --- ## Pre-Wired Mock Variables After calling `super.setup()`, the following MockBox-created stubs are available: | Variable | Type | Description | |---|---|---| | `variables.model` | CFC instance | The model under test | | `variables.mockLogger` | Mock object | Stand-in for `LogBox.getLogger()` | | `variables.mockLogBox` | Mock object | Stand-in for the full LogBox instance | |