Flashseer BBS
 
»
游客:  注册 | 登录 | 会员 | 统计 | 帮助 | 翻译计划 | FlashSeer QQ群 | FlashSeer QQ群历史记录

RSS 订阅当前论坛  

标题: FlexUnit 的用法  
  本主题被作者加入到他/她的 Blog 中  
 
胡矿
管理员
Rank: 9Rank: 9Rank: 9


UID 3
精华 1
积分 10
帖子 160
阅读权限 200
注册 2006-8-10
状态 离线
FlexUnit 的用法

FlexUnit 是一个开源的AS3单元测试框架,这样用:

1.先下载 FlexUnit,在附件当中。
2.解开压缩包
3.新建一个 Flex Project(Basic那种),在类路径配置当中点击“Add SWC”, 选择解开的压缩包当中的
./bin/flexunit.swc(截图请看附件当中的”图一“)
然后点击 finish
4.写一个入口类:FlexUnitEntry.as,取别的名字也可以。只要和 MXML 当中对应就行

package {
        import flexunit.framework.TestSuite;

       
        public class FlexUnitEntry {
                public static function suite():TestSuite {
                           var ts:TestSuite = new TestSuite();
                          
                           //To-do:在这里加入你要测试的测试用例
                          
                           return ts;
                   }
        }
}
4.在 项目的 MXML 当中这样写:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="*"
                                xmlns:flexunit="flexunit.flexui.*"
                                creationComplete="onCreationComplete()">
        <mx:Script>
                <![CDATA[
                        import flexunit.framework.TestSuite;
                       
                        private function onCreationComplete() :void {
                                this.runnerBase.test = this.suite();
                                this.runnerBase.startTest();
                        }
                       
                        private function suite():TestSuite {
                                var ts:TestSuite = new TestSuite();
                                ts.addTest(FlexUnitEntry.suite());
                                return ts;
                        }
                       
                ]]>
        </mx:Script>

        <!-- flexunit provides a very handy default test runner GUI -->
        <flexunit:TestRunnerBase id="runnerBase" width="100%" height="100%" />

</mx:Application>
5.写一个测试类,这里建议用这样的模版:

package {
        import flexunit.framework.TestCase;
        import flexunit.framework.TestSuite;
        import flexunit.framework.Assert;

        public class MyFlexUnitTest extends TestCase {
               
                public static function suite() :TestSuite {
                        var ts:TestSuite = new TestSuite();
                       
                        ts.addTest(new MyFlexUnitTest("testAssertTrue"));//用要测试的方法名作为构造函数参数传入
                        ts.addTest(new MyFlexUnitTest("testAssertEquals"));
                       
                        return ts;
                }
               
                public function MyFlexUnitTest(methodName:String=null) {
                        super(methodName);
                }
               
                //方法名不是像JUnit那样必须用 test.... 开头,不过最好这样写
                public function testAssertTrue() :void {
                        Assert.assertTrue(false);//肯定报错
                }
               
                public function testAssertEquals() :void {
                        Assert.assertEquals(1.0, 1.0);
                }
        }
}
6.在入口类(FlexUnitEntry)当中加入这个测试用例,这样:

public static function suite():TestSuite {
        var ts:TestSuite = new TestSuite();

        //To-do:在这里加入你要测试的测试用例                       
        ts.addTest(MyFlexUnitTest.suite());
                          
        return ts;
                   }
7.运行项目的 MXML 就看到结果了(建议用Debug模式运行)。如果是绿条,说明所有测试通过,如果是红的,说明有错误。会有显示。
项目编译的时候建议设置 -default-size 600 440 这样FlexUnit 的界面显示就比较完全了。
运行结果如图(附件中的“图二”)

以上:)


 附件: 您所在的用户组无法下载或查看附件
2006-9-25 09:37#1
查看资料  Blog  发短消息  QQ  顶部
 
ASever (FinalBug)
版主
Rank: 7Rank: 7Rank: 7


UID 8
精华 1
积分 10
帖子 135
阅读权限 100
注册 2006-8-10
来自 Sichuan
状态 离线
Flex不会用,很多天没来,纯UP一下。^_^



Final Bug . CN
2006-9-25 17:40#2
查看资料  访问主页  Blog  发短消息  QQ  顶部
 
Dream
0级
Rank: 1



UID 11
精华 0
积分 0
帖子 9
阅读权限 10
注册 2006-8-10
状态 离线
組件漂亮,
不知道flash9裡會是怎樣的組件呢??




梦总是停在你触手可及的地方,所以你要有勇气伸出你渴望成功的手……
2006-10-19 16:03#3
查看资料  发短消息  顶部
       





ICP证:粤ICP备06089120号;版权所有 flashseer.org 保留所有权flashseer.org
Processed in 0.123167 second(s), 7 queries

所有时间为 GMT+8, 现在时间是 2010-9-4 06:37
清除 Cookies - 联系我们 - Flashseer.org - Archiver - WAP