Introducing Jasmine-Flex

I have been developing software using Test Driven Development (TDD) for over three years now.  I usually use traditional xUnit style testing frameworks (NUnit, JUnit, jsUnit, FlexUnit, cppUnit, etc) because they are the most accessible frameworks out there.

In reality, though, my TDD style has evolved into more of a Behavior Driven Development (BDD) style.  I specify how my software behaves opposed to writing tests against the inputs/outputs of a given function.  Although this can be a bit awkward with the xUnit style of testing, it can be done ANDI have done so successfully for quite some time.

While I am doing this, I always think to the times when I develop in Ruby.  When in Ruby, I don’t use the standard xUnit tool.  Instead, I use RSpec.  RSpec allows me to organize my tests (specifications) more organically and within context.  The result is a more expressive, better organized test suite more suited for BDD-style development.

Lately, however, I have been spending a lot of time with the Flex framework.  I wanted to find a BDD context specification tool for that environment but I came up empty.  I got excited when I found one in JavaScript, and it gave me hope.

Enter Jasmine

Jasmine is a BDD testing tool written in JavaScript and used in all sorts of environments including Ruby on Rails and Node.js.  I put my feet to the fire and hacked out a port of this code base to ActionScript.  I am pleased to announce that Jasmine-Flex is ready to go!

Using Jasmine-Flex is simple:

  1. Create a new Flex project (Flash or Air)
  2. Download JasmineFlex.swc and put it in your libs folder.
  3. Put the TrivialFlexReporterView in your application and set autoExecute to true.
  4. Add your specs using the script tag
  5. Run the app.

Here is a step-by-step example:

1. Create a new Flex project (Flash or Air)

step1

2. Download JasmineFlex.swc and put it in your libs folder

step2

3. Put the TrivialFlexReporterView in your application and set autoExecute to true.

step3

4. Add your specs using the script tag

step4a

step4b

5. Run the app

step5

You are up and running

Now that you have a Jasmine testing environment up and running, you continue to use Jasmine to write specs, watch them fail, and make them pass.  Add as many spec suites as you need using the script tag (step 3).  Before you know it, you will have a rich suite of executable specifications!

Need more information?

  • See the documentation on the Jasmine-Flex site.
  • Take a look at an example project.
  • See the specs for the Jasmine project (Jasmine was built using Jasmine!).
  • Check out The RSpec Book. Most of the concepts apply directly to Jasmine.

Tags: , , ,

5 Responses to “Introducing Jasmine-Flex”

  1. James Ward says:

    This is awesome stuff! Thanks Brian!

  2. John Dewar says:

    Nice. Does it require Flex or will it work in a pure-AS3 project?

  3. admin says:

    Yes, I think it should work in a pure-AS3 project. Except, of course, for the “TrivialFlexReporter”. You would probably want to use the “TrivialConsoleReporter” or the “TrivialTraceReporter” instead… or create your own reporter…

  4. how do i have to load the trace/console or whatever reporter in a pure as3 project? would be cool to have the reporting in the movie, not on the console, how would i have to do that? its described for flex above, but i would like to have a pure as3 movie (air+browser)
    thanks in advance

Leave a Reply