5 Replies Latest reply on Dec 12, 2010 3:55 AM by Atarsh

    metadata for NOT getting an exception?

    Atarsh

      Hey,

      I saw in the documentation (or was it the quickstart guide..?) that I can have metadata on a test saying it should pass if a certain error is met (expects).

      I want to have a test verifying my app DOESN'T crash on a certain input - meaning I don't get an error.

      Is there a built in way (like, metadata or something) to test that, or do I have to wrap my test code in try..catch statements?

       

      thanks,

       

      Atar.

        • 1. Re: metadata for NOT getting an exception?
          mlabriola Level 4

          Atar,

           

          I am not sure I understand your question. You want a test that fails when an error occurs, yes? If that is what you are asking for that is what FlexUnit does all of the time. You execute some code, if it throws an error, the test fails.

           

          Is that what you were asking or am I missing the point?

          Mike

          • 2. Re: metadata for NOT getting an exception?
            Atarsh Level 1

            the normal flow is that a test fails if you get a wrong answer from a method, what I get is a flash error (that's how my code is built).

            if I get a flash error, it obviously crashes the testing application.

            I'm trying to make sure the app doesn't crash, even on wrong input - so I need a way to tell a test method that if an error is met, it should fail - but without crashing. for that matter, it doesn't matter if the error is a built in flash error or a custom error.

            • 3. Re: metadata for NOT getting an exception?
              mlabriola Level 4

              Make a test that looks like this:

               

              [Test]

              public function myTest():void {

               

                var date:Date;

               

                trace( date.hours );

              }

               

              This will throw a flash error because date was never instantiated. You will see it will show up as a failed test in FlexUnit and you will not get a crash at the top level. The only way you can be getting a top level crash on an error is if you are doing something asynchronous in your code. Since asynchronous operations are governed by the flash player and not flexunit, an error will be displayed by flash player.

               

              If your code is constructed in such a way that it can be separated into units for testing, then you can look at the asynchronous APIs in FlexUnit to help manage this.

               

              I may be totally wrong here, and I apologize in advance if I am. However, I not that you keep saying application, which makes me think you might be testing something larger, like a whole application. FlexUnit is really just for testing code units, so if you are doing more application level tests you might want to look at a tool like FlexMonkey or RIATest.

               

              Mike

              • 4. Re: metadata for NOT getting an exception?
                Atarsh Level 1

                first of all - thanks for your efforts

                I will try to run the test you suggested soon, and let you know how things go.

                 

                at the moment we don't have any application level testing, I'm just trying to make sure the initial part doesn't crash on malformed input.

                and after all, isn't an application just a lot of code units ?

                 

                thanks again,

                Atar.

                • 5. Re: metadata for NOT getting an exception?
                  Atarsh Level 1

                  Well, I tried that, and what do you know, you were right

                  I wrote the test after fixing the crash in the real code, and probably got things all mixed upon the way.

                   

                  Thanks anyway, again

                   

                  Atar