FlexUnit小小应用

本文介绍如何使用FlexUnit进行单元测试。通过实例演示了如何设置测试环境、编写测试用例及运行测试。具体包括创建SimpleTest类继承自TestCase并定义测试方法,以及SimpleConverter类作为被测试对象。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

            类似JUnit,之前稍微研究过。现在简单介绍下FlexUnit的简单应用:首先去adobe open source下载FLEXUNIT

            网址:http://opensource.adobe.com/wiki/display/flexunit/Downloads

            在你建立好的项目中导入该swc,(此步骤就不介绍了^-^).

            index.mxml (亦可是别的mxml)模拟:

            <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:flexui="flexunit.flexui.*" 
                     creationComplete="init()"   layout="absolute" >

                    <mx:Script>
                            <![CDATA[
                                      //import some class yourself

                                     private function createTestSuite():TestSuite
                                     {
                                            var testSuite:TestSuite = new TestSuite();
                                            testSuite.addTest(new SimpleTest("testConvertIsDesc"));

                                            return testSuite;
                                     }

                                     internal function init():void
                                    {
                                            ///////////////////////////TestUnit//////////////////////////////
                                           testRunner.test = createTestSuite();
                                           testRunner.startTest();

                                            /////////////////////////////////////////////////////////////////
                                    }
    
                             ]]>
                      </mx:Script>

                      <flexui:TestRunnerBase id="testRunner" width="100%" height="100%"/>

              </mx:Application>

             SimpleTest.as------>code

             package com.jerry.tests
             {
                    import flexunit.framework.TestCase;
                    import flexunit.framework.Assert;

                    public class SimpleTest extends TestCase
                    {
                             public function SimpleTest(methodName:String=null)
                            {
                                    super(methodName);
                             }
                             // 测试方法 ConvertToIsDesc
                              public function testConvertIsDesc():void
                            {
                                 var simple:SimpleConverter = new SimpleConverter();
                                 var desc:String = simple.ConvertToIsDesc(1);
                                 Assert.assertEquals(desc, "是");
                     }

              }

              SimpleConverter.as---->code

              package com.jerry.tests
              {
                           public class SimpleConverter
                          {
                                public function SimpleConverter()
                               {
                                          // 构造函数

                               }
                               // 需要测试的方法
                              public function ConvertToIsDesc(i:int):String
                               {
                                        var isDesc:String = "否";
                                        if(i == 1)
                                        {
                                               isDesc = "是";
                                        }
            
                                        return isDesc;
                                }


                        }
                    }
                }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值