Class: Buildr::AS3::Test::FlexUnit4

Inherits:
TestFramework::AS3
  • Object
show all
Defined in:
lib/buildr/as3/test/flexunit4.rb

Overview

FlexUnit4 test framework.

Support the following options:

  • :player -- ["air","flash"] defines the player to run the tests, when not set it chooses based on the projects compiler.

  • :haltonFailure -- [Boolean] stop unit-testing on error

  • :verbose -- [Boolean] print additional info

  • :localTrusted -- [Boolean] some sandbox thing

  • :htmlreport -- [Boolean] set to true if you want to create a JUnit HTML report

Constant Summary

VERSION =
'4.1.0_RC2-4'
FLEX_SDK_VERSION =
'4.1.0.16076'

Class Method Summary (collapse)

Instance Method Summary (collapse)

Class Method Details

+ (Object) flexunit_taskdef

:nodoc:



44
45
46
# File 'lib/buildr/as3/test/flexunit4.rb', line 44

def flexunit_taskdef #:nodoc:
  "com.adobe.flexunit:flexunitUnitTasks:jar:#{VERSION}"
end

+ (Object) swc_dependencies



48
49
50
51
52
53
54
55
56
57
# File 'lib/buildr/as3/test/flexunit4.rb', line 48

def swc_dependencies
  [
      "com.adobe.flexunit:flexunit:swc:as3_#{FLEX_SDK_VERSION}:#{VERSION}",
      "com.adobe.flexunit:flexunit:swc:flex_#{FLEX_SDK_VERSION}:#{VERSION}",
      "com.adobe.flexunit:flexunit-aircilistener:swc:#{FLEX_SDK_VERSION}:#{VERSION}",
      "com.adobe.flexunit:flexunit-cilistener:swc:#{FLEX_SDK_VERSION}:#{VERSION}",
      "com.adobe.flexunit:flexunit-flexcoverlistener:swc:#{FLEX_SDK_VERSION}:#{VERSION}",
      "com.adobe.flexunit:flexunit-uilistener:swc:#{FLEX_SDK_VERSION}:#{VERSION}"
  ]
end

Instance Method Details

- (Object) run(tests, dependencies)

:nodoc:



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/buildr/as3/test/flexunit4.rb', line 69

def run(tests, dependencies) #:nodoc:

  report_dir = task.project._(:reports, FlexUnit4.to_sym)
  FileUtils.mkdir_p report_dir

  project_dir = Dir.getwd
  Dir.chdir report_dir

  taskdef = Buildr.artifact(FlexUnit4.flexunit_taskdef)
  taskdef.invoke

  player = "air" if [:airmxmlc, :airompc].include?(task.project.compile.compiler)
  player ||= "flash"
  player || options[:player]

  Buildr.ant("flexunit4test") do |ant|

    ant.property :name => "FLEX_HOME",
                 :location=>task.project.compile.options[:flexsdk].home

    ant.taskdef :resource => "flexUnitTasks.tasks",
                :classpath => taskdef.to_s

    ant.flexunit :player => player,
                 :haltonFailure => false || options[:haltonFailure],
                 :verbose => true || options[:verbose],
                 :localTrusted => true || options[:localTrusted],
                 :swf => task.project.get_as3_output(task.project.test.compile.target, task.project.test.compile.options)

    ant.taskdef :name=>'junitreport',
                :classname=>'org.apache.tools.ant.taskdefs.optional.junit.XMLResultAggregator',
                :classpath=>Buildr.artifacts(JUnit.ant_taskdef).each(&:invoke).map(&:to_s).join(File::PATH_SEPARATOR)
    unless options[:htmlreport] == false
      ant.junitreport :todir => report_dir do
        ant.fileset :dir => report_dir do
          ant.include :name => "TEST-*.xml"
        end
        ant.report :format => "frames", :todir => report_dir + "/html"
      end
    end


    Dir[report_dir+"/TEST-*.xml"].each do |xml_report|
      doc = REXML::Document.new File.new(xml_report)
      name = doc.elements["testsuite"].attributes["name"]
      failures = Integer(doc.elements["testsuite"].attributes["failures"])
      errors = Integer(doc.elements["testsuite"].attributes["errors"])
      tests -= [name] unless failures + errors == 0
    end

  end
  Dir.chdir project_dir
  tests
end

- (Object) tests(dependencies)

:nodoc:



60
61
62
63
64
65
66
67
# File 'lib/buildr/as3/test/flexunit4.rb', line 60

def tests(dependencies) #:nodoc:
  candidates = []
  task.project.test.compile.sources.each do |source|
    files = Dir["#{source}/**/*Test.as"] + Dir["#{source}/**/*Test.mxml"]
    files.each { |item| candidates << File.dirname(item).gsub!(source+"/", "").gsub!("/", ".")+"."+File.basename(item, '.*') }
  end
  candidates
end