如何从动作脚本库退出空中应用程序?

时间:2010-05-14 21:07:59

标签: flex air flexcover

我正在尝试以下内容,但偶尔会定义nativeApp。

var nativeApp:Object =  getDefinitionByName("flash.desktop.NativeApplication");
nativeApp.nativeApplication.exit();

我很困惑,为什么有时候getDefinitionByName(“flash.desktop.NativeApplication”)会解析,有时则不会解析。

我正在尝试解决此问题,以解决flexcover中的以下问题 - code.google.com/p/flexcover/issues/detail?id=33

更新 - 这是我试图修复的类:http://code.google.com/p/flexcover/source/browse/trunk/CoverageAgent/src/com/allurent/coverage/runtime/AbstractCoverageAgent.as CoverageAgent.swc是一个动作脚本库,由单元测试调用退出用于确定单元测试代码覆盖率的flexcover air应用程序。 flexcover air应用程序仅退出大约一半的时间,这导致我们的maven构建成功执行的问题。

3 个答案:

答案 0 :(得分:2)

NativeApplication.nativeApplication.exit();

答案 1 :(得分:1)

关于FlexCover - 您有时看到它工作的原因而不是其他人的原因是CoverageAgent旨在退出单元测试,它不会与CoverageViewer进行通信。我创建了自己的FlexCoverListener,它通过本地连接向CoverageViewer发送退出消息。以下是代码。

package org.flexunit.listeners
{
import flash.events.EventDispatcher;

import org.flexunit.listeners.closer.FlexCoverCloser;
import org.flexunit.runner.IDescription;
import org.flexunit.runner.Result;
import org.flexunit.runner.notification.Failure;
import org.flexunit.runner.notification.IAsyncStartupRunListener;
import org.flexunit.runner.notification.ITemporalRunListener;

public class FlexCoverListener extends EventDispatcher implements IAsyncStartupRunListener,    
ITemporalRunListener
{
  import com.allurent.coverage.runtime.CoverageManager;

  public function FlexCoverListener()
  {
  }

  public function get ready():Boolean 
  {
      return true;
  }

  public function testTimed( description:IDescription, runTime:Number ):void
  {

  }


  public function testRunFinished( result:Result ):void 
  {
      CoverageManager.agent.recordCoverage("SR_TESTS_COMPLETE");
  }

  public function testFinished( description:IDescription ):void {}

  public function testRunStarted( description:IDescription ):void {}


  public function testStarted( description:IDescription ):void{}


  public  function testFailure( failure:Failure ):void{}


  public function testAssumptionFailure( failure:Failure ):void{}


  public function testIgnored( description:IDescription ):void{}
  }
  }

您可以通过在TestRunner中执行以下操作,将上述侦听器添加到您的测试中:

core.addListener(new FlexCoverListener());
var core : FlexUnitCore = new FlexUnitCore();

最后但最重要的是,我更改了recordCoverage中的AbstractCoverageAgent方法,如下所示:

/**
     * Record the execution of a single coverage key; called by
     * the global coverage() function.
     */
    public function recordCoverage(key:String):void
    {
        if(key == "SR_TESTS_COMPLETE")
        {
            exit();    
        }
        else if (isNaN(coverageMap[key]++))
        {
            // The map must not have contained this key yet, so enter an
            // execution count of 1.  Subsequent calls will autoincrement without
            // returning NaN.
            //
            coverageMap[key] = 1;
        }
    }

答案 2 :(得分:0)

nativeAppilcation是一个静态字段。它不需要在对象上调用。因此,您无需致电getDefinitionByName("flash.desktop.NativeApplication")

只需按如下方式调用exit:

NativeApplication.nativeApplication.exit();

Flash Builder或Flash Pro将为您提供该库 如果您未使用IDE,请导入库:

import flash.desktop.NativeApplication;