For the complete documentation index, see llms.txt. This page is also available as Markdown.

Testing

Test your BoxLang module with TestBox and integrate testing into your CI/CD pipeline

Test your module using TestBox for BoxLang code, JUnit for Java code, or a combination of both.

TestBox Testing

TestBox is BoxLang's testing framework. Place tests in your module's tests/ directory.

Test Structure

my-module/
├── tests/
│   ├── Application.bx        # TestBox test harness
│   ├── specs/
│   │   ├── MyBIFTest.bx      # BDD-style tests
│   │   └── MyComponentTest.bx
│   └── resources/
│       └── fixtures/

BDD-Style Test Example

File: tests/specs/GreetBIFTest.bx

describe( "Greet BIF", () => {
    beforeEach( () => {
        variables.result = greet( "World" )
    } )

    it( "returns a greeting string", () => {
        expect( variables.result ).toBeString()
    } )

    it( "includes the name in the greeting", () => {
        expect( variables.result ).toInclude( "World" )
    } )

    it( "uses custom greeting when provided", () => {
        var custom = greet( name = "World", greeting = "Hi" )
        expect( custom ).toInclude( "Hi" )
    } )
} )

xUnit-Style Test Example

Running Tests

JUnit Testing (Java Modules)

For Java-heavy modules, use JUnit 5 with standard Gradle test configuration:

Run JUnit tests:

Integration Testing

Test your module loaded in a running BoxLang runtime:

CI/CD Integration

GitHub Actions Example

Test Best Practices

1

Test Module Isolation

Verify your module loads cleanly with no side effects. Test both load and unload cycles.

2

Test Error Handling

Write tests for invalid inputs, missing dependencies, and edge cases.

3

Test With Other Modules

Verify compatibility by testing alongside modules your module depends on or commonly coexists with.

4

Mock External Dependencies

Use MockBox to mock external services in tests:

Next Steps

Last updated

Was this helpful?