Blog

Luis Majano

October 15, 2013

Spread the word


Share your thoughts

We are so pleased to bring you another addition to our Box collection of products: TestBox.  TestBox is a next generation testing framework for ColdFusion 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 integrates with MockBox for mocking and stubbing. It also supports xUnit style of testing and MXUnit compatibilities.  At this point TestBox has been released as a 1.0.0 Alpha and can be downloaded from our main downloads page and it has been also integrated into our "development" branch for the ColdBox platform as well.  As you will see, TestBox also leverages Closures extensively to provide nice clear syntaxes in your tests.

Features At A Glance

  • Here are a simple listing of features TestBox brings to the table:
  • 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
  • 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
  • Clickable suite titles to filter test execution
  • Direct MXUnit replacement
  • Much more!

Like with anything we do, it is completely documented in three separate guides:

  1. TestBox Complete Docs
  2. TestBox BDD Primer
  3. TestBox xUnit Primer

Finally, TestBox is also a direct drop-replacement for MXUnit as well.  We have fully documented how you can re-use your tests within TestBox and also migrate them if you need to.  Check out some cool BDD action you will be able to do with TestBox:

describe("Some Included TestBox Matchers:", function() {

     describe("The 'toBe' matcher", function() {
          it("works for simple values", function() {
               coldbox = 1;
               expect( coldbox ).toBe( 1 );
               expect( coldbox ).notToBe( 5 );
          });

          it("works for complex values too (arrays,structs,queries,objects)", function() {
               expect( [1,2] ).toBe( [1,2] );
               expect( { name="luis", awesome=true} ).toBe( { awesome=true, name="luis" } );
               expect( this ).toBe( this );
               expect( queryNew("") ).toBe( queryNew("") );
          });
     });

     it("The 'toBeWithCase' matches strings with case equality", function() {
          expect( 'hello' ).toBeWithCase( 'hello' );
          expect( 'hello' ).notToBeWithCase( 'HELLO' );
     });

     it("The 'toBeTrue' and 'toBeFalse' matchers are used for boolean operations", function() {
          coldbox_rocks = true;
          expect( coldbox_rocks ).toBeTrue();
          expect( !coldbox_rocks ).toBeFalse();
     });

     it("The 'toBeNull' expects null values", function() {
          foo = "bar";
          expect( javaCast("null", "") ).toBeNull();
          expect( foo ).notToBeNull();
     });

     it("The 'toBeInstanceOf' expects the object to be of the same class or inheritance or implementation", function() {
          expect( new coldbox.system.testing.Assertions ).toBeInstanceOf( 'coldbox.system.testing.Assertions' );
          expect( this ).notToBeInstanceOf( 'coldbox.system.testing.MockBox' );
     });

     it("The 'toMatch' matcher is for regular expressions with case sensitivity", function() {
          message = 'foo man choo';

          expect( message ).toMatch( '^foo' );
          expect( message ).toMatch( '(man)' );
          expect( message ).notToMatch( 'superman' );
     });

     it("The 'toMatchNoCase' matcher is for regular expressions with no case sensitivity", function() {
          message = 'foo man choo';

          expect( message ).toMatch( '^FOO' );
          expect( message ).toMatch( '(MAN)' );
          expect( message ).notToMatch( 'SuperMan' );
     });

     describe("The 'toBeTypeOf' matcher evaluates using the CF isValid() function", function() {
          it("works with direct calls", function() {
               expect( [1,2] ).toBeTypeOf( 'Array' );
               expect( { name="luis", awesome=true} ).toBeTypeOf( 'struct' );
               expect( this ).toBeTypeOf( 'component' );
               expect( '03/01/1990' ).toBeTypeOf( 'usdate' );
          });

          it("works with dynamic calls as well", function() {
               expect( [1,2] ).toBeArray();
               expect( { name="luis", awesome=true} ).toBeStruct();
               expect( this ).toBeComponent();
               expect( '03/01/1990' ).toBeUsDate();
          });
     });

     it("The 'toBeEmpty' checks emptyness of simple or complex values", function() {
          expect( [] ).toBeEmpty();
          expect( { name="luis", awesome=true} ).notToBeEmpty();
          expect( '' ).toBeEmpty();
     });

     it("The 'toHaveLength' checks size of simple or complex values", function() {
          expect( [] ).toHaveLength( 0 );
          expect( { name="luis", awesome=true} ).toHaveLength( 2 );
          expect( 'Hello' ).toHaveLength( 5 );
     });

     it("The 'toHaveKey' checks for existence of keys in structs", function() {
          expect( { name="luis", awesome=true} ).toHaveKey( 'name' );
     });

     it("The 'toHaveDeepKey' checks for existence of keys anywhere in structs", function() {
          expect( { name="luis", { age=35, awesome=true } } ).toHaveKey( 'age' );
     });

     it("The 'toThrow' checks if the actual call fails", function() {
          expect( function(){
               new calculator().divide( 40, 0 );
          }).toThrow();

          expect( function(){
               new calculator().divide( 40, 0 );
          }).toThrow( regex="zero" );
     });

});

What's to come

TestBox is being actively developed and we need your feedback in order to do a full release.  We still have some issues pending with MXUnit compatibility, asynchronous testing, NodeJS and GruntJS integration (Tha'ts Right!), and much more.  So subscribe to our mailing list to stay on top of things or this blog's RSS feed.

Add Your Comment

Recent Entries

ColdBox 7.2.0 Released

ColdBox 7.2.0 Released

ColdBox, a widely used development platform for ColdFusion (CFML), has unveiled version 7.2. Packed with compelling new features, bug fixes, and enhancements, this release is designed to empower developers by boosting productivity, refining scheduled task capabilities, and enhancing the overall reliability and efficiency of application development. This article will delve into the key highlights of ColdBox 7.2 and elucidate how these advancements can positively impact developers in their daily coding endeavors.

Luis Majano
Luis Majano
November 20, 2023
Into the Box 2023 Series on CFCast

Into the Box 2023 Series on CFCast

Excitement is in the air as we unleash the highly anticipated ITB 2023 series exclusively for our valued CFCast subscribers – and the best part? It's FREE for CFCast members! Now is the perfect time if you haven't joined the CFCast community yet. Plus, we've got an incredible End-of-Year deal that's too good to miss

Maria Jose Herrera
Maria Jose Herrera
November 20, 2023
Ortus Deals are Finally Here!

Ortus Deals are Finally Here!

The much-anticipated Ortus End-of-the-Year Sale has arrived, and it's time to elevate your development experience! Whether you're a seasoned developer, a tech enthusiast, or someone on the lookout for top-notch projects, Ortus has something special in store for you. Brace yourself for incredible discounts across a wide array of products and services, including Ortus annual events, books, cutting-edge services, and more.

Maria Jose Herrera
Maria Jose Herrera
November 15, 2023