LogoLogo
HomeAPIBlog
3.0.0-SNAPSHOT
3.0.0-SNAPSHOT
  • INTRODUCTION
    • Getting Started
      • Running Local Development Servers
      • Beginner Tutorial: Hello World
      • Beginner Tutorial: Hello Database
      • Tutorial: Wheels, AJAX, and You
    • Frameworks and Wheels
    • Requirements
    • Manual Installation
    • Upgrading
    • Screencasts
  • Command Line Tools
    • CLI Overview
    • Quick Start Guide
    • Command Reference
      • Core Commands
        • wheels init
        • wheels info
        • wheels reload
        • wheels deps
        • wheels destroy
        • wheels watch
      • Code Generation
        • wheels generate app
        • wheels generate app-wizard
        • wheels generate controller
        • wheels generate model
        • wheels generate view
        • wheels generate property
        • wheels generate route
        • wheels generate resource
        • wheels generate api-resource
        • wheels generate frontend
        • wheels generate test
        • wheels generate snippets
        • wheels scaffold
      • Database Commands
        • wheels dbmigrate info
        • wheels dbmigrate latest
        • wheels dbmigrate up
        • wheels dbmigrate down
        • wheels dbmigrate reset
        • wheels dbmigrate exec
        • wheels dbmigrate create blank
        • wheels dbmigrate create table
        • wheels dbmigrate create column
        • wheels dbmigrate remove table
        • wheels db schema
        • wheels db seed
      • Testing Commands
        • wheels test
        • wheels test run
        • wheels test coverage
        • wheels test debug
      • Configuration Commands
        • wheels config list
        • wheels config set
        • wheels config env
      • Environment Management
        • wheels env
        • wheels env setup
        • wheels env list
        • wheels env switch
      • Plugin Management
        • wheels plugins
        • wheels plugins list
        • wheels plugins install
        • wheels plugins remove
      • Code Analysis
        • wheels analyze
        • wheels analyze code
        • wheels analyze performance
        • wheels analyze security
      • Security Commands
        • wheels security
        • wheels security scan
      • Performance Commands
        • wheels optimize
        • wheels optimize performance
      • Documentation Commands
        • wheels docs
        • wheels docs generate
        • wheels docs serve
      • CI/CD Commands
        • wheels ci init
      • Docker Commands
        • wheels docker init
        • wheels docker deploy
      • Deployment Commands
        • wheels deploy
        • wheels deploy audit
        • wheels deploy exec
        • wheels deploy hooks
        • wheels deploy init
        • wheels deploy lock
        • wheels deploy logs
        • wheels deploy proxy
        • wheels deploy push
        • wheels deploy rollback
        • wheels deploy secrets
        • wheels deploy setup
        • wheels deploy status
        • wheels deploy stop
    • CLI Development Guides
      • Creating Commands
      • Service Architecture
      • Migrations Guide
      • Testing Guide
  • Working with Wheels
    • Conventions
    • Configuration and Defaults
    • Directory Structure
    • Switching Environments
    • Testing Your Application
    • Using the Test Environment
    • Contributing to Wheels
    • Submitting Pull Requests
    • Documenting your Code
  • Handling Requests with Controllers
    • Request Handling
    • Rendering Content
    • Redirecting Users
    • Sending Files
    • Sending Email
    • Responding with Multiple Formats
    • Using the Flash
    • Using Filters
    • Verification
    • Event Handlers
    • Routing
    • URL Rewriting
      • Apache
      • IIS
      • Tomcat
      • Nginx
    • Obfuscating URLs
    • Caching
    • Nesting Controllers
    • CORS Requests
  • Displaying Views to Users
    • Pages
    • Partials
    • Linking Pages
    • Layouts
    • Form Helpers and Showing Errors
    • Displaying Links for Pagination
    • Date, Media, and Text Helpers
    • Creating Custom View Helpers
    • Localization
  • Database Interaction Through Models
    • Object Relational Mapping
    • Creating Records
    • Reading Records
    • Updating Records
    • Deleting Records
    • Column Statistics
    • Dynamic Finders
    • Getting Paginated Data
    • Associations
    • Nested Properties
    • Object Validation
    • Object Callbacks
    • Calculated Properties
    • Transactions
    • Dirty Records
    • Soft Delete
    • Automatic Time Stamps
    • Database Migrations
      • Migrations in Production
    • Using Multiple Data Sources
  • Plugins
    • Installing and Using Plugins
    • Developing Plugins
    • Publishing Plugins
  • Project Documentation
    • Overview
  • External Links
    • Source Code
    • Issue Tracker
    • Sponsor Us
    • Community
Powered by GitBook
LogoLogo
On this page
  • Synopsis
  • Description
  • Arguments
  • Options
  • Examples
  • Run all tests
  • Run specific test file
  • Run tests in directory
  • Watch mode
  • Run specific bundles
  • Filter by labels
  • Use different reporter
  • Save results to file
  • Test Structure
  • Writing Tests
  • Model Test Example
  • Controller Test Example
  • Test Configuration
  • /tests/Application.cfc
  • Watch Mode
  • Reporters
  • Simple (Default)
  • Text
  • JSON
  • JUnit
  • TAP
  • Filtering Tests
  • By Bundle
  • By Label
  • By Name Filter
  • Exclude Patterns
  • Parallel Execution
  • Code Coverage
  • Test Helpers
  • Database Strategies
  • Transaction Rollback
  • Database Cleaner
  • Fixtures
  • CI/CD Integration
  • GitHub Actions
  • Pre-commit Hook
  • Performance Tips
  • Common Issues
  • Out of Memory
  • Test Pollution
  • Flaky Tests
  • See Also

Was this helpful?

Edit on GitHub
Export as PDF
  1. Command Line Tools
  2. Command Reference
  3. Testing Commands

wheels test run

Run TestBox tests for your application with advanced features.

Synopsis

wheels test run [spec] [options]

Description

The wheels test run command executes your application's TestBox test suite with support for watching, filtering, and various output formats. This is the primary command for running your application tests (as opposed to framework tests).

Arguments

Argument
Description
Default

spec

Specific test spec or directory

All tests

Options

Option
Description
Default

--watch

Watch for changes and rerun

false

--reporter

TestBox reporter

simple

--recurse

Recurse directories

true

--bundles

Test bundles to run

--labels

Filter by labels

--excludes

Patterns to exclude

--filter

Test name filter

--outputFile

Output results to file

--verbose

Verbose output

false

--help

Show help information

Examples

Run all tests

wheels test run

Run specific test file

wheels test run tests/models/UserTest.cfc

Run tests in directory

wheels test run tests/controllers/

Watch mode

wheels test run --watch

Run specific bundles

wheels test run --bundles=models,controllers

Filter by labels

wheels test run --labels=unit,critical

Use different reporter

wheels test run --reporter=json
wheels test run --reporter=junit
wheels test run --reporter=text

Save results to file

wheels test run --reporter=junit --outputFile=test-results.xml

Test Structure

Standard test directory layout:

/tests/
├── Application.cfc      # Test configuration
├── models/             # Model tests
│   ├── UserTest.cfc
│   └── ProductTest.cfc
├── controllers/        # Controller tests
│   ├── UsersTest.cfc
│   └── ProductsTest.cfc
├── views/             # View tests
├── integration/       # Integration tests
└── helpers/          # Test helpers

Writing Tests

Model Test Example

component extends="testbox.system.BaseSpec" {

    function run() {
        describe("User Model", function() {
            
            beforeEach(function() {
                // Reset test data
                application.wirebox.getInstance("User").deleteAll();
            });
            
            it("validates required fields", function() {
                var user = model("User").new();
                expect(user.valid()).toBeFalse();
                expect(user.errors).toHaveKey("email");
                expect(user.errors).toHaveKey("username");
            });
            
            it("saves with valid data", function() {
                var user = model("User").new(
                    email="test@example.com",
                    username="testuser",
                    password="secret123"
                );
                expect(user.save()).toBeTrue();
                expect(user.id).toBeGT(0);
            });
            
            it("prevents duplicate emails", function() {
                var user1 = model("User").create(
                    email="test@example.com",
                    username="user1"
                );
                
                var user2 = model("User").new(
                    email="test@example.com",
                    username="user2"
                );
                
                expect(user2.valid()).toBeFalse();
                expect(user2.errors.email).toContain("already exists");
            });
            
        });
    }

}

Controller Test Example

component extends="testbox.system.BaseSpec" {

    function run() {
        describe("Products Controller", function() {
            
            it("lists all products", function() {
                // Create test data
                var product = model("Product").create(name="Test Product");
                
                // Make request
                var event = execute(
                    event="products.index",
                    renderResults=true
                );
                
                // Assert response
                expect(event.getRenderedContent()).toInclude("Test Product");
                expect(event.getValue("products")).toBeArray();
            });
            
            it("requires auth for create", function() {
                var event = execute(
                    event="products.create",
                    renderResults=false
                );
                
                expect(event.getValue("relocate_URI")).toBe("/login");
            });
            
        });
    }

}

Test Configuration

/tests/Application.cfc

component {
    this.name = "WheelsTestingSuite" & Hash(GetCurrentTemplatePath());
    
    // Use test datasource
    this.datasources["wheelstestdb"] = {
        url = "jdbc:h2:mem:wheelstestdb;MODE=MySQL"
    };
    this.datasource = "wheelstestdb";
    
    // Test settings
    this.testbox = {
        testBundles = "tests",
        recurse = true,
        reporter = "simple",
        labels = "",
        options = {}
    };
}

Watch Mode

Watch mode reruns tests on file changes:

wheels test run --watch

Output:

[TestBox Watch] Monitoring for changes...
[TestBox Watch] Watching: /tests, /models, /controllers

[14:23:45] Change detected: models/User.cfc
[14:23:45] Running tests...

✓ User Model > validates required fields (12ms)
✓ User Model > saves with valid data (45ms)
✓ User Model > prevents duplicate emails (23ms)

Tests: 3 passed, 0 failed
Time: 80ms

[TestBox Watch] Waiting for changes...

Reporters

Simple (Default)

wheels test run --reporter=simple
  • Colored console output

  • Shows progress dots

  • Summary at end

Text

wheels test run --reporter=text
  • Plain text output

  • Good for CI systems

  • No colors

JSON

wheels test run --reporter=json
{
    "totalDuration": 523,
    "totalSpecs": 25,
    "totalPass": 24,
    "totalFail": 1,
    "totalError": 0,
    "totalSkipped": 0
}

JUnit

wheels test run --reporter=junit --outputFile=results.xml
  • JUnit XML format

  • For CI integration

  • Jenkins compatible

TAP

wheels test run --reporter=tap
  • Test Anything Protocol

  • Cross-language format

Filtering Tests

By Bundle

# Run only model tests
wheels test run --bundles=models

# Run multiple bundles
wheels test run --bundles=models,controllers

By Label

it("can authenticate", function() {
    // test code
}).labels("auth,critical");
# Run only critical tests
wheels test run --labels=critical

# Run auth OR api tests
wheels test run --labels=auth,api

By Name Filter

# Run tests matching pattern
wheels test run --filter="user"
wheels test run --filter="validate*"

Exclude Patterns

# Skip slow tests
wheels test run --excludes="*slow*,*integration*"

Parallel Execution

Run tests in parallel threads:

wheels test run --threads=4

Benefits:

  • Faster execution

  • Better CPU utilization

  • Finds concurrency issues

Code Coverage

Generate coverage reports:

wheels test run --coverage --coverageOutputDir=coverage/

View report:

open coverage/index.html

Test Helpers

Create reusable test utilities:

// /tests/helpers/TestHelper.cfc
component {
    
    function createTestUser(struct overrides={}) {
        var defaults = {
            email: "test#CreateUUID()#@example.com",
            username: "user#CreateUUID()#",
            password: "testpass123"
        };
        
        return model("User").create(
            argumentCollection = defaults.append(arguments.overrides)
        );
    }
    
    function loginAs(required user) {
        session.userId = arguments.user.id;
        session.isAuthenticated = true;
    }
    
}

Database Strategies

Transaction Rollback

function beforeAll() {
    transaction action="begin";
}

function afterAll() {
    transaction action="rollback";
}

Database Cleaner

function beforeEach() {
    queryExecute("DELETE FROM users");
    queryExecute("DELETE FROM products");
}

Fixtures

function loadFixtures() {
    var users = deserializeJSON(
        fileRead("/tests/fixtures/users.json")
    );
    
    for (var userData in users) {
        model("User").create(userData);
    }
}

CI/CD Integration

GitHub Actions

- name: Run tests
  run: |
    wheels test run --reporter=junit --outputFile=test-results.xml
    
- name: Upload results
  uses: actions/upload-artifact@v2
  with:
    name: test-results
    path: test-results.xml

Pre-commit Hook

#!/bin/bash
# .git/hooks/pre-commit

echo "Running tests..."
wheels test run --labels=unit

if [ $? -ne 0 ]; then
    echo "Tests failed. Commit aborted."
    exit 1
fi

Performance Tips

  1. Use labels for fast feedback

    wheels test run --labels=unit  # Fast
    wheels test run --labels=integration  # Slow
  2. Parallel execution

    wheels test run --threads=4
  3. Watch specific directories

    wheels test run tests/models --watch
  4. Skip slow tests during development

    wheels test run --excludes="*integration*"

Common Issues

Out of Memory

# Increase memory
box server set jvm.heapSize=1024
box server restart

Test Pollution

  • Use beforeEach/afterEach

  • Reset global state

  • Use transactions

Flaky Tests

  • Avoid time-dependent tests

  • Mock external services

  • Use fixed test data

See Also

Previouswheels testNextwheels test coverage

Last updated 2 days ago

Was this helpful?

- Run framework tests

- Generate coverage

- Debug tests

- Generate test files

wheels test
wheels test coverage
wheels test debug
wheels generate test