我正在使用 Flex 4.11.0 和 AIR 4.0 构建一个移动应用程序。我的 IDE 是 Flash Builder 4.7。我编写了很多单元测试,其中一些使用了 AIR 功能,例如文件系统访问。
我正在尝试将该项目集成到 jenkins 上的 CI 工作中。我有一个执行以下操作的 ANT 脚本:
- 编译
- 安卓包装
- iOS 包装
- 生成 ASDOC
我现在想要的是编写一个 ANT-Task 来启动我的单元测试并生成 XML 或 HTML 格式的报告,之后 Jenkins 可以对其进行解析。
我尝试了以下方法: - 遵循http://tutorials.digitalprimates.net/flexunit/Unit-16.html上的教程并让示例正常工作。但是,这是一个 Flash 项目,而不是 AIR 项目!- 阅读https://cwiki.apache.org/confluence/display/FLEX/FlexUnit+Ant+Task上的文档,从 git@github.com:flexunit/flexunit.git 下载并构建 FlexUnit 代码以获取 FlexUnit4AIRCIListener。 swc - 从各地阅读互联网上的大量信息,但没有找到答案(我确实找到了一些提示,但很多信息已经过时或引用了死链接)
到目前为止,我有以下内容:
<taskdef resource="flexUnitTasks.tasks" classpath="${basedir}\libs\flexUnitTasks-4.1.0.jar" />
<target name="test" >
<echo>Testing...</echo>
<echo>==========</echo>
<!-- 1. Compile FlexUnit-Application -->
<mxmlc file="${PROJECT.src}\FlexUnit.mxml" output="FlexUnit.swf" >
<load-config filename="D:\tools\sdk\flex\4.11.0_AIR4.0\frameworks\air-config.xml" append="true" />
<source-path path-element="${PROJECT.src}" />
<source-path path-element="${basedir}\test" />
<library-path dir="${PROJECT.libs}" append="true">
<include name="**/*.swc" />
<include name="**/*.ane" />
</library-path>
<library-path dir="D:\tools\sdk\flex\4.11.0_AIR4.0\frameworks\libs\air" append="true">
<include name="airglobal.swc" />
</library-path>
<compiler.verbose-stacktraces>true</compiler.verbose-stacktraces>
<compiler.headless-server>true</compiler.headless-server>
</mxmlc>
<!-- 2. Run the compiled SWF -->
<flexunit swf="FlexUnit.swf"
player="air"
timeout="180000"
toDir="${OUTPUT.root}\flexUnit"
haltonfailure="false"
verbose="true"
localTrusted="true"
/>
<!-- 3. Generate readable JUnit-style reports -->
<junitreport todir="${OUTPUT.root}\flexUnit">
<fileset dir="${OUTPUT.root}\flexUnit">
<include name="TEST-*.xml" />
</fileset>
<report format="frames" todir="${OUTPUT.root}\flexUnit\html" />
</junitreport>
</target>
以下是我的 FlexUnit.mxml-Application 的相关部分:
protected function onCreationComplete(event:FlexEvent):void
{
core = new FlexUnitCore();
core.addListener(new AirCIListener());
core.run(currentRunTestSuite());
}
public function currentRunTestSuite():Array
{
var testsToRun:Array = new Array();
testsToRun.push(test.suites.CLXSatelliteTestSuite);
return testsToRun;
}
第 1 步。从 ANT-Task 工作(至少我得到了 FlexUnit.swf)。但是,在<flexunit>
-Task 中启动 SWF 失败:
VerifyError: Error #1014: Class flash.filesystem::File could not be found.
控制台输出:[flexunit] 生成默认值 ... [flexunit] 使用默认工作目录 [D:\workspaces\flex\projects\clx-satellite] [flexunit] 使用以下设置进行测试运行:[flexunit] FLEX_HOME: [D:\tools\sdk\flex\4.11.0_AIR4.0] [flexunit] haltonfailure: [false] [flexunit] headless: [false] [flexunit] display: [99] [flexunit] localTrusted: [true] [flexunit ] 播放器:[flash] [flexunit] 端口:[1024] [flexunit] swf:[D:\workspaces\flex\projects\clx-satellite\FlexUnit.swf] [flexunit] 超时:[180000ms] [flexunit] toDir: [D:\workspaces\flex\projects\clx-satellite\deploy\flexUnit] [flexunit] 设置服务器进程 ... [flexunit] 启动服务器 ... [flexunit] 在端口 [1024] 上打开服务器套接字。[flexunit] 等待客户端连接... [flexunit] 操作系统:[Windows] [flexunit] 启动播放器:[flexunit] 使用参数执行 'rundll32':[flexunit] 'url.dll,FileProtocolHandler' [flexunit] 'D:\workspaces\flex\projects\clx-satellite \FlexUnit.swf' [flexunit] 围绕可执行文件和参数的 ' 字符是 [flexunit] 不是命令的一部分。[flexunit] 客户端已连接。[flexunit] 将入站缓冲区大小设置为 [262144] 字节。[flexunit] 接收数据 ... [flexunit] 向播放器发送确认以开始发送测试数据 ... [flexunit] [flexunit] 停止服务器 ... [flexunit] 到达测试数据结束,向播放器发送确认... FileProtocolHandler' [flexunit] 'D:\workspaces\flex\projects\clx-satellite\FlexUnit.swf' [flexunit] 围绕可执行文件和参数的 ' 字符是 [flexunit] 不是命令的一部分。[flexunit] 客户端已连接。[flexunit] 将入站缓冲区大小设置为 [262144] 字节。[flexunit] 接收数据 ... [flexunit] 向播放器发送确认以开始发送测试数据 ... [flexunit] [flexunit] 停止服务器 ... [flexunit] 到达测试数据结束,向播放器发送确认... FileProtocolHandler' [flexunit] 'D:\workspaces\flex\projects\clx-satellite\FlexUnit.swf' [flexunit] 围绕可执行文件和参数的 ' 字符是 [flexunit] 不是命令的一部分。[flexunit] 客户端已连接。[flexunit] 将入站缓冲区大小设置为 [262144] 字节。[flexunit] 接收数据 ... [flexunit] 向播放器发送确认以开始发送测试数据 ... [flexunit] [flexunit] 停止服务器 ... [flexunit] 到达测试数据结束,向播放器发送确认... [flexunit] 将入站缓冲区大小设置为 [262144] 字节。[flexunit] 接收数据 ... [flexunit] 向播放器发送确认以开始发送测试数据 ... [flexunit] [flexunit] 停止服务器 ... [flexunit] 到达测试数据结束,向播放器发送确认... [flexunit] 将入站缓冲区大小设置为 [262144] 字节。[flexunit] 接收数据 ... [flexunit] 向播放器发送确认以开始发送测试数据 ... [flexunit] [flexunit] 停止服务器 ... [flexunit] 到达测试数据结束,向播放器发送确认...
BUILD FAILED
D:\workspaces\flex\projects\clx-satellite\build.xml:148:
java.util.concurrent.ExecutionException: could not close client/server socket
当我包含一个不使用File
-Class 的测试时,测试工作并且我得到一个类似的错误 ( ReferenceError: Error #1065: Variable flash.desktop::NativeApplication is not defined.
),但至少测试运行通过并且我得到 XML 输出。在我看来,FlexUnit 与 AIR 并不真正兼容,尽管我player=air
在任务中使用。
你们中是否有人有通过 ANT 为 AIR 应用程序(可能是移动应用程序)运行 FlexUnit 单元测试的工作示例?