- 浏览: 330140 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
wangjun0603:
学习了,写的真好!
native2ascii的简单应用 -
qq672076266:
...
native2ascii的简单应用 -
loyalboys:
...
native2ascii的简单应用 -
hanjinting1004:
...
Flex开发者需要知道的10件事 -
管好你家猫:
学了,文章,
native2ascii的简单应用
Problem
How to create a FlexUnit TestCase class that can be used to test code.
怎么创建能用于测试代码的flex单元测试用例
Solution
Create a class that extends TestCase and include one or more public methods whose name starts with test.
创建一个类继承TestCase,类中包括一或者多个以test开头的公共的方法
Detailed explanation
1. Create an ActionScript class that extends TestCase
Create a new ActionScript class that extends TestCase. The remainder of this recipe will use the following RegExpTest as the example:
package { import flexunit.framework.TestCase; public class RegExpTest extends TestCase { } }
2. Create a method whose name starts with test
Add the following method to RegExpTest:
public function testRegExp():void { }
3. Make one or more assertions
- assertEquals: Compare with ==
- assertTrue: Check condition is true
- assertNull: Check if null
- assertStrictlyEquals: Compare with ===
FlexUnit also provides various convenience assertions which test for the opposite condition such as assertFalse and assertNotNull. See the Assert API documentation included with FlexUnit for a complete list of assertions.
Each assertion function can take an optional String as the first argument which will be included in the assertion output should the assertion fail. This String will be prefixed before the default "expected X but was Y" failure message.
When writing assertions keep in mind that if an assertion fails, the rest of the test method will not be executed.
TestCase extends Assert which defines all of the assert functions. This allows subclasses of TestCase to directly call the assert functions. The following code demonstrate the various assertion methods and should be added to the testRegExp function:
var regExp:RegExp = new RegExp("a", "i"); assertFalse(regExp.test("b")); assertFalse("regExp doesn't match", regExp.test("b")); assertNull(regExp.exec("b")); assertNull("regExp doesn't match", regExp.exec("b")); assertNotNull(regExp.exec("Apple")); assertNotNull("regExp matches", regExp.exec("Apple")); assertTrue(regExp.exec("Apple") is Array); assertTrue("regExp exec returned an Array", regExp.exec("Apple") is Array); assertEquals("A", regExp.exec("Apple")[0]); assertEquals("regExp matched A in Apple", "A", regExp.exec("Apple")[0]); assertStrictlyEquals(regExp, regExp); assertStrictlyEquals("regExp object identity", regExp, regExp);
4. Add additional test methods
Add new test methods to the TestCase to test other logical groups of operations. It is convention that each test method focus on testing a specific operation or task. For example when testing create, retrieve, update, and delete operations each one should be put into its own test method such as testCreate, testRetrieve, etc. This way should assertions start to fail, multiple failures will be reported helping diagnosis the issue.
It is important to keep in mind that the order that the test methods in a TestCase are run is random. Each test should create its own data and make no assumptions about another test having already run.
5. Add the TestCase to the TestSuite
The last step is to add the newly created TestCase to the TestSuite.
See the Adding a TestCase to a TestSuite recipe.
Reference
The final ActionScript file:
package { import flexunit.framework.TestCase; public class RegExpTest extends TestCase { public function testRegExp():void { var regExp:RegExp = new RegExp("a", "i"); assertFalse(regExp.test("b")); assertFalse("regExp doesn't match", regExp.test("b")); assertNull(regExp.exec("b")); assertNull("regExp doesn't match", regExp.exec("b")); assertNotNull(regExp.exec("Apple")); assertNotNull("regExp matches", regExp.exec("Apple")); assertTrue(regExp.exec("Apple") is Array); assertTrue("regExp exec returned an Array", regExp.exec("Apple") is Array); assertEquals("A", regExp.exec("Apple")[0]); assertEquals("regExp matched A in Apple", "A", regExp.exec("Apple")[0]); assertStrictlyEquals(regExp, regExp); assertStrictlyEquals("regExp object identity", regExp, regExp); } } }
发表评论
-
应用避免访问浏览器缓存
2011-05-12 17:33 1319项目经常遇到这么个问题:程序做了改动之后,由于浏览 ... -
flex皮肤资源
2011-05-05 15:28 1273如果要找flex皮肤,这里的皮肤真是多。http: ... -
flex利用asdoc生成doc和制作chm
2011-04-02 17:33 1593How to set up ASDoc in Flex Bui ... -
restrict的应用实例
2011-04-02 11:54 10921. 限制某个字符的输入,用符号 ^ 跟上要限制的 ... -
flex中as、instanceof、is、 typeof用法
2011-03-24 09:48 4524“as” 我主要用它做类型转化 假设有一个类叫做 ... -
在Chart上画平均线的三种方法
2011-02-16 14:52 1387在Chart上画平均线的三种方法 ... -
Flex Frameworks
2010-11-12 15:32 971Some say that if a t ... -
flex4国际化
2010-11-11 16:56 2090国际化变得如此简单 <?xml versi ... -
使用ToolTipManager自定义tooltip
2010-11-05 14:52 2585直接贴代码,一看就懂。 <?xml version=& ... -
flex 校验
2010-11-05 14:41 1001①flex中的校验可以使用mx.validator ... -
Flex中的fx、mx和s命名空间
2010-11-05 13:12 3339Flex 4带给我们的 ... -
socket中writeUTF和writeUTFBytes的区别
2010-11-03 10:25 2764Q:用writeUTF发送数据的时候,后台多 ... -
修改flex默认loading
2010-10-18 13:51 2485一: SWF Flex 2 PreloaderSWF ... -
AIR文件操作
2010-09-26 10:01 2877AIR文件操作(一):AIR文件基础 AI ... -
ActionScript 3.0 Socket编程
2010-09-17 17:25 1144在使用ActionScript3.0进行编程的时候需要注 ... -
as 对象深度拷贝
2010-08-20 10:32 953这是一篇关于as3中对象深度拷贝的问题今天自己总结下,便 ... -
as3corelib
2010-04-29 20:10 1459google code :http://code. ... -
FusionCharts
2010-04-28 19:26 2340无意中接触到这个产品FusionCharts,3D ... -
flex datagrid自动换行
2010-04-19 17:10 2858以为datagrid的自动换行有多复杂,其实 ... -
让Enter键盘起到Tab键盘的功能
2010-04-19 16:25 821让Enter键盘起到Tab键盘的功能 ...
相关推荐
Flex当前炙手可热的RIA技术,FlexUnit使Flex开发的单元测试成为可能。FlexUnit的目标和思想与JUnit都是差不多的,在此不赘述。FlexUnit也经历了几个版本,目前最新的稳定版是1.0RC版,已经支持了标注式的test,非常...
flexunit-4.1.0_RC2-4-4.1.0.16076.zip,flexunit 4
lexunit 详细简单用例 里面带有flexunit.swc 包
FlexUnit4熟悉与使用,自己做的...不是抄网上的,实用
flexunit ant版本里面有ant的详细配置
flexunit-服务器FlexUnit Node.js 服务器。 该模块接受来自 FlexUnit CIListener 的连接并使用给定的报告器生成结果。使用示例 var fuserver = require ( ... createServer ( reporter ) ;server . listen ( 8080 ) ;
Flex调试专用插件! Flex Builder4 也就 Flash Builder 中会自带的那个!
grunt-flexunit flexunit-server 的 Grunt 插件。 额外要求 除了 npm 模块依赖项之外,运行grunt-flexunit还需要以下内容。 要用于打开swf文件的浏览器 目前仅支持Firefox 浏览器的 Flash Player 插件 xvfb-run ...
咕flex挠单位一个Grunt任务插件,用于为基于Adobe Flex / ActionScript / MXML / Flash / AIR / etc的应用运行FlexUnit测试。入门这个插件需要~0.4.2 如果您以前从未使用过 ,请务必查看《指南》,因为它说明了如何...
flex开发,做为测试使用,方便提供给flex开发人员测试
它与 FlexUnit 测试流程和 Flex Framework UI 组件完美配合。 Flash 有一项特殊能力——输出看起来总是一样的。 快速、轻便且易于使用 [ Test(async, ui) ] public function defaultColor() : void { var ...
与 Macromedia Flex 一起使用的 actionscript 2.0 单元测试框架。 基于 Nunit 等测试框架,全面支持测试 Flex 应用程序,包括异步 Web 服务请求。
查看 FlexUnit 测试运行的结果 第 8 章: 使用 Flex 开发应用程序 使用 Flex 开发应用程序的基本工作流 构建用户界面 生成事件处理函数 访问数据服务 监视访问数据服务的应用程序 使用 Flex 库项目 创建自定义 ...
本文首先阐述了选择Red5禾IFlex进行网页游戏开发的原因,并介绍和分析了两者的概念和原理,并针对网页游戏的难题提出一些解决办法。然后,本文运用UML等方法对...最后,本文用JUnit和FlexUnit对系统进行了单元测试,得
Flex on Java Bernerd Allmon and Jeremy Anderson MEAP Began: May 2008 Softbound print: July 2010 (est.) | 375 pages ISBN: 1933988797 ...10. Testing your Flex app with FlexUnit 11. Flex on Grails
著名的xMock框架的ActionScript3实现,是flexUnit框架的扩展。
Part 1: Getting started 1. Some Flex with your Java 2. Beginning with Java 3. Getting Rich with Flex 4. Connecting to Web Services ...10. Testing your Flex app with FlexUnit 11. Flex on Grails
1 18 跟我StepByStep学FLEX教程------FlexUnit4 alpha 1 0 5 4发布 1 19 跟我StepByStep学FLEX教程------Demo9之FlexUnit4 1 20 跟我StepByStep学FLEX教程------Demo10之DataGrid 1 21 跟我StepByStep学FLEX教程-...
Flash开发人员单元测试在可视树中显示FlexUnit4轨迹的插件。 工作正在进行中
它是简单的 AsUnit/FlexUnit 4 风格的 UI-Unit 框架,但不用于测试。 它是一种快速访问和验证 UI 实现的工具。 | | 例子 赛跑者: public class DemoRunner extends Sprite { public function DemoRunner() { ...