TextBox logo

TestBox

Testing & Mocking Framework

TestBox Overview

TestBox is a next generation testing framework for ColdFusion (CFML) that is based on BDD (Behavior Driven Development) for providing a clean obvious syntax for writing tests. It contains not only a testing framework, runner, assertions and expectations library but also ships with MockBox, A Mocking & Stubbing Framework. It also supports xUnit style of testing and MXUnit compatibilities.

Installation

You can get started quickly with TestBox and MockBox in any ColdFusion (CFML) application by leveraging CommandBox, our CLI and package manager. Just following the simple commands below to install the latest stable or bleeding edge version of TestBox.

							// Install latest stable version
							box install testbox --saveDev
						
							// Install bleeding edge version
							box install testbox@be --saveDev
						

You can also visit https://cfdocs.org/testbox for a quick reference guide.

BDD & xUnit Syntax

TestBox supports a readable Behavior Driven Development syntax and the more traditional xUnit style syntax as well.

 

If you are not so familiar with BDD, please download our BDD RefCard to give you a quick head start.

Download BDD Refcard
                                    describe("A spec", function() {
                                        beforeEach(function() {
                                            testbox = 22;
                                            application.wirebox = new wirebox.system.ioc.Injector();
                                        });
                                        afterEach(function() {
                                            testbox = 0;
                                            structDelete( application, "wirebox" );
                                        });
                                    
                                        // Using gherkins style declarations
                                        scenario( "Get box volume", function(){
                                            given( "I have entered a width of 20
                                                And a height of 30
                                                And a depth of 40", function(){
                                                when( "I run the calculation", function(){
                                                    then( "the result should be 24000", function(){
                                                        // call the method with the arguments and test the outcome
                                                        expect( myObject.myFunction(20,30,40) ).toBe( 24000 );
                                                    });
                                                });
                                            });
                                        });
                                    
                                        it("can have more than one expectation and talk to scopes", function() {
                                            expect( testbox ).toBe( 22 );
                                            expect( application.wirebox.getInstance( 'MyService' ) ).toBeComponent();
                                        });
                                    
                                        describe("nested inside a second describe", function() {
                                            beforeEach(function() {
                                                awesome = 22;
                                            });
                                            afterEach(function() {
                                                awesome = 22 + 8;
                                            });
                                            it("can reference both scopes as needed ", function() {
                                                expect( testbox ).toBe( awesome );
                                            });
                                        });
                                    
                                        it("can be declared after nested suites and have access to nested variables", function() {
                                            expect( awesome ).toBe( 30 );
                                        });
                                    });
                                
 

If you are not so familiar with TDD and xUnit, please download our TDD RefCard to give you a quick head start.

Download TDD Refcard
                                    component displayName="TestBox xUnit suite" labels="railo,cf"{
                                        /*********************************** LIFE CYCLE Methods ***********************************/
                                    
                                        function beforeTests(){
                                            application.salvador = 1;
                                        }
                                    
                                        function afterTests(){
                                            structClear( application );
                                        }
                                    
                                        function setup(){
                                            request.foo = 1;
                                        }
                                    
                                        function teardown(){
                                            structClear( request );
                                        }
                                    
                                        /*********************************** Test Methods ***********************************/
                                        function testIncludes(){
                                            $assert.includes( "hello", "HE" );
                                            $assert.includes( [ "Monday", "Tuesday" ] , "monday" );
                                        }
                                    
                                        function testNotIncludes(){
                                            $assert.notIncludes( "hello", "what" );
                                            $assert.notIncludes( [ "Monday", "Tuesday" ] , "Friday" );
                                        }
                                    
                                        function testIsNotEmpty(){
                                            $assert.isNotEmpty( [1,2] );
                                            $assert.isNotEmpty( {name="luis"} );
                                            $assert.isNotEmpty( "HelloLuis" );
                                            $assert.isNotEmpty( querySim( "id, name
                                                1 | luis") );
                                        }
                                    
                                        function testSkipped() skip{
                                            $assert.fail( "This Test should fail" );
                                        }
                                    
                                        boolean function isRailo(){
                                            return structKeyExists( server, "railo" );
                                        }
                                    
                                        function testSkippedWithConstraint() skip="isRailo"{
                                            $assert.fail( "This Test should fail" );
                                        }
                                    
                                        function testAssertShortcut() {
                                            assert( application.salvador == 1 );
                                        }
                                    
                                        function testisTrue() {
                                            $assert.isTrue( 1 );
                                        }
                                    
                                    
                                    /*********************************** NON-RUNNABLE Methods ***********************************/     
                                    
                                        function nonStandardNamesWillNotRun() {
                                            fail( "Non-test methods should not run" );
                                        }
                                    
                                        private function privateMethodsDontRun() {
                                            fail( "Private method don't run" );
                                        }
                                    
                                    }
                                

Capabilities

Here are some of the major features of TestBox and MockBox

  • BDD style testing
  • xUnit style testing
  • Testing life-cycle methods
  • MockBox integration for mocking and stubbing
  • Ability to extend and create custom test runners
  • Ability to extend and create custom test reporters
  • Extensible reporters, bundled with tons of them:
    • JSON
    • XML
    • JUnit 4 XML
    • Text (80's style)
    • Console
    • TAP (Test Anything Protocol)
    • Simple HTML
    • Min - Minimalistic Heaven
    • Raw
    • CommandBox
  • Asynchronous testing
  • Multi-suite capabilities
  • Test skipping
  • Suite skipping
  • Dynamic skipping support via runtime executions
  • Test one or more suites exclusively
  • Test one or more tests/specs exclusively
  • Test labels and tagging
  • Testing debug output stream
  • Clickable suite titles to filter test execution
  • Much more!

Read More

Professional Support & Training

If you get stuck or need to get up to speed with testing, mocking, continuous integration or anything BDD, we would love to help. You can get professional support or training directly from the TestBox Team anywhere in the world.

cfcasts

CBOX-205 : BDD & TDD CFML Development

CBOX-205 is one of our core courses that focus on testing principles, TDD (Test Driven Development), BDD (Behavior Driven Development), mocking and automation. See more...

1 - 2 Days

$1,399.00

Per Student

BOOK
waveup-lightBlue
waveup-lightBlue
Got Questions?

Got Questions?

Please contact us at consulting@ortussolutions.com for further information or click the button below and send us a quick message.

CONTACT US