Skip to main content
Known Participant
February 25, 2010
Answered

flexunit 4 fails for me

  • February 25, 2010
  • 4 replies
  • 4988 views

I am simply running an Assert.assertTrue call and it says it fails, here is my code:

package sampleSuite.tests
{
     import org.flexunit.*;
     public class TestCase1
     {
          [Before]
           public function setUp():void
           {
           }

           [After]
           public function tearDown():void
           {
           }

           [BeforeClass]
           public static function setUpBeforeClass():void
           {
           }

           [AfterClass]
           public static function tearDownAfterClass():void
           {     
           }

          [Test]
          public function testFunction():void{
               Assert.assertTrue();

          }
     }
}

Pretty straightforward code, but it keeps giving me an error expected true but returns false. TIA.

This topic has been closed for replies.
Correct answer mlabriola

Todd:

assertTrue() takes an argument. You are not passing one, so you are saying assertTure( null ), which FlexUnit is correctly interpreting as not true and failing an assertion.

try assertTrue( true ) or assertTrue( 1 == 1 ) and you will see that it works just fine.

Mike

4 replies

Participant
July 11, 2010

Thanks for the quick reply, it seems my real problem must have been a corrupt workspace file somewhere. Just to be sure everything was cool, I rebuilt the workspace / project from scratch. Low and behod, no more errors. Thanks again.

- Paul

Participating Frequently
July 11, 2010

No problem. Let me know if I can help in any other way.

Participant
July 11, 2010

I am not sure if this is the right place to post this, but I have found two problems with assertThat() in FB4:

1. FB4 will not register a test containing (only) an org.hamcrest.assertThat() as a test, and therefore will not run in, (or as in my case, since I was only using hamcrests assertThat, it will tell you that there are not tests to run in your file)

2. org.flexunit.assertThat() explodes on chained matchers. The following causes a stack trace with org.flexunit.assertThat(), but works fine with org.hamcrest.assertThat():

[Test]
        public function should_chain_matchers_together():void
        {
            assertThat("good", both(equalTo("good")).and(not(equalTo("bad"))));
            assertThat("good", either(equalTo("good")).or(not(equalTo("bad"))));

        }

3. is there anyway to get an updated flexunitextended.swc such that it 'is in sync' with the most recent flexunit4 (or 4.1 beta as the case may be)?


Anyways, I am blocked on moving my team to unit testing in FB4 at the moment because of these issues. Thanks for anything you can find out -- please let me know if there is anything I can do to work around/fix these issues.

Participating Frequently
July 11, 2010

>>1. FB4 will not register a test containing (only) an org.hamcrest.assertThat() as a test, and therefore will not run in, (or as in my case, since I was only >>using hamcrests assertThat, it will tell you that there are not tests to run in your file)

I am not sure what you mean by this. Anything marked with [Test], even a completely blank method, is a valid test:

[Test]

public function doNothing():void

{

}

That is valid.  Do you mean you are putting an assertThat() in a method but *not* marking it with [Test]? The definition of a test is based on metadata, not contents of the method.

>>2. org.flexunit.assertThat() explodes on chained matchers. The following causes a stack trace with org.flexunit.assertThat(), but works fine >>with org.hamcrest.assertThat():

I take your code exactly as listed in your post and it ran correctly for me. I have included the entire test case for your reference:

package

{

import org.flexunit.assertThat;

import org.hamcrest.core.both;

import org.hamcrest.core.either;

import org.hamcrest.core.not;

import org.hamcrest.object.equalTo;

public class MyTestCase

{

[Test]

public function should_chain_matchers_together():void

{

assertThat("good", both(equalTo("good")).and(not(equalTo("bad"))));

assertThat("good", either(equalTo("good")).or(not(equalTo("bad"))));

}

}

}

If this fails for you, then let me know your version numbers for both the hamcrest and flexunit swc and I will make sure that I test against the same version.

>>3. is there anyway to get an updated flexunitextended.swc such that it 'is in sync' with the most recent flexunit4 (or 4.1 beta as the case may be)?

flexunitextended.swc just holds Adobe's components for interfacing with FlexUnit. It doesn't hold any flexunit resources itself so it doesn't change regardless if you use 4.0 or the betas, etc. If you look in the same directory include that links in the extended classes, you will see something like:

flexunit-core-flex-4.0.0.2-sdk3.5.0.12683.swc

This is the swc that you actually need to change. Flash Builder will also show you the path on your drive where that file exists. You can replace that file by literally renaming it to a .old file on the file system and copying a newer swc into that directory. That is the easiest way. If you feel comfortable, you can instead edit those link properties to remove adobe's entry and instead link your own swc and then relink adobe's directly as opposed to a directory. This is more complicated than it should be but I am pushing Adobe to fix this in future versions.

Mike

mlabriolaCorrect answer
Participating Frequently
February 25, 2010

Todd:

assertTrue() takes an argument. You are not passing one, so you are saying assertTure( null ), which FlexUnit is correctly interpreting as not true and failing an assertion.

try assertTrue( true ) or assertTrue( 1 == 1 ) and you will see that it works just fine.

Mike

Known Participant
February 25, 2010

I have another problem too. I placed the hamcrest.swc in my library and tried to make calls to hamcrest calls and they return errors. I downloaded the latest flexunit4, but still running into problems. Here is my code:

[Test( description = "This checks movieclips for textfields" )]
          public function checkTexts():void
          {
               var arr:Array = ChildObjects.findChildTextFields(mc);
                   assertThat( arr, hasItems(tf) );
               
          }

I was able to get an AssertEquals to register as correct, but have failed in everything else I have tried. I am using Flex Builder 3.

Todd

Participating Frequently
February 25, 2010

Well, I don't know what the rest of your code looks like, but if I do a simple test of hamcrest using an array and finding things, it works well. I would suggest perhaps verifying that your installation works with something simple like an array of numbers, finding a number, etc.

I assure you the code works well, so if you want to post the whole test, including where mx and tf are defined, I can look further.

Mike

Participating Frequently
February 25, 2010

Todd,

Can you post your code for that last example if you get time? It might be nice to have an example here in the forums that people can look back to.

Thanks,

Mike