Create FlexUnit Tests Quickly in IntelliJ IDEA

Do you know how to navigate from a class to its test and back again or how to create a FlexUnit test quickly with IntelliJ IDEA 11? Let me tell you.

First of all make sure that flexunit.swc is within your module dependencies:

and just press Ctrl+Shift+T (Cmd+Shift+T on Mac) or select Navigate | Test from main menu:

Options to generate setUp() and tearDown() as well as test method stubs are available in test creation dialog:

And here you are!

Adding more tests is easy as well. Press Alt+Insert (Ctrl+Enter on Mac) and select to generate test method:

Hint: To be sure that test classes and FlexUnit classes won’t occasionally appear in production SWF/SWC follow these two good style suggestions:

  • configure dependency on FlexUnit library with ‘Test’ scope (as shown on the first screenshot)
  • keep test classes in a separate source folder marked as test source folder:

Test with pleasure!

This entry was posted in New Features and tagged , , , . Bookmark the permalink.

9 Responses to Create FlexUnit Tests Quickly in IntelliJ IDEA

  1. Alejandro says:

    Are the steps different for Intellij 10? After adding the FlexUnit swc, I press (cmd+shift+T) and I don’t see an option to “Create New Test”. Also, “Test” option is grey in the main menu. (GoTo >> Test)

    Am I missing something?

  2. Alexander Doroshko says:

    @Alejandro The answer is in the first sentence of this blog post :)

  3. David J McClelland says:

    Can FlexUnitTestRunnerUI and the flexui namespace be used in IDEA or are these tied to Flash Builder?

  4. Alexander Doroshko says:

    @David Tied to FB

  5. David J McClelland says:

    I was able to get the test result screen to appear in browser, which is what I really wanted.

    BTW, using V11 of IDEA: before Create New Test step in instructions above you should create a folder named “test” and designate it as your test source directory. RightClick->sel->Mark Directory As->Test Source Root. Then folder turns to green shade, and when the Create Test dialog appears you do not fill in destination package. You will get a prompt to pick src or testSrc after you accept the dialog. Otherwise my test classes kept getting put in the history directory (?).

  6. Randy Gupta says:

    I did as you described in your post. But when I try to run the test it says: “Cannot resolve file …”

    However there is nothing else inside the test but

    trace(“This is a test!”);

    So I am wondering how to resolv this?

    Btw. it is actually a mobile application, but sind flex unit doesn’t support mobile applications I switched the configuration to Desktop/Library.

  7. Alexander Doroshko says:

    @Randy Can you please give the screenshot of the error message? Please use our forum (http://devnet.jetbrains.net/community/idea/ideacommunity) or issue tracker (http://youtrack.jetbrains.net) or send a message to support.

  8. ArAgorrn says:

    Hi,

    When I try to run a test class, the compiler doesn’t seem to see id. I get this message
    :

    [MyProject- flexunit]: Error code: 1172: Definition test.exceptions:ExceptionsSchedulerTest could not be found.
    [MyProject- flexunit]: Error code: 1120: Access of undefined property ExceptionsSchedulerTest.

    As if the compiler was unable to see my test class. I don’t know what to change.

  9. Alexander Doroshko says:

    @ArAgorrn I’ve got the same question via support channel and answered there. Support or forum are the best places to ask such questions. Short answer is: you have overwritten source paths via additional compiler options (-source-path=locale/{locale}), so compiler doesn’t look into real source folder for the ExceptionsSchedulerTest class. You need to remove -source-path from additional compiler options. IntelliJ IDEA uses {locale} token automatically during compilation if locales and source folders are configured correctly. Locales list is configured at Compiler Options tab of the build configuration (Project Structure dialog). Each subfolder of ‘locales’ folder must be configured as a source folder.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>