2 Replies Latest reply on Nov 5, 2009 4:43 PM by markdemi

    Looping test with data

    markdemi

      I have an object that essentially takes a string and output another string.  I wanted to create a single test with a loop and have an array of object that represents the strings to be compared.  However, after doing it I realized that it won't work since it will only test up to the first failure and than exception out.  Is there a way to do this without creating a test method for each pair of strings.  I would really like to avoid that since there will be tons of them.  Plus, my goal will be to store this data in an external xml file.

       

      Here's the code I have with the loop.

       

              [Test (Description="Chapter 1 - Numbers")] 
              public function number():void {  
                  var tests:Array = [
                      { eq:"59*0=0",                speak:"59 times 0 equals 0"} ,
                      { eq:"102+2,214+15=2,331",    speak:"102 plus 2,214 plus 15 equals 2,331"},
                      { eq:"3--2",                speak:"3 minus negative 2"}
                  ]
                 
                  for each (var test:Object in tests) {
                      Assert.assertEquals(test.speak,getMathSpeak(test.eq));
                  }   
              }

        • 1. Re: Looping test with data
          mlabriola Level 4

          What you are looking for is parameterized testing. This will be in our next release but isnt available yet.

           

          A somewhat cheap way you could handle this now is to compare each example in the loop and push the results onto an array. When the loop is done, if the array is empty, then you do nothing and the test passed. If the array has values, then you can call Assert.fail and pass it the array converted to a string.

           

          You will still only get one success or failure, but at least you will have some detail about why it failed.

           

          the parameterized testing is likely still a month or more away from its debut. It is a tricky problem due to the need to unwind it across flash player frames.

           

          mike

          1 person found this helpful
          • 2. Re: Looping test with data
            markdemi Level 1

            Thanks for the quick answer.  I guess for now, I'll just make separate methods.  When the  parameterized feature comes out, I'll convert my code.  What I'll do is may my array static.  Then, I can just copy and paste a bunch of tasks that use the array with an index.  That way it will be easier to convert later.

             

            Nice work on this.  I put together my first set of tests in a couple of hours.  I'm looking forward to getting future updates.

             

            Mark