Class: Test::Unit::UI::Fox::TestRunner

Class | Test::Unit::UI::Fox::TestRunner
In: | test/unit/ui/fox/testrunner.rb
Parent: | Object

Runs a Test::Unit::TestSuite in a Fox UI. Obviously, this one requires you to have Fox (www.fox-toolkit.org/fox.html) and the Ruby Fox extension (fxruby.sourceforge.net/) installed.

### Methods

add_fault attach_to_mediator clear_fault create_application create_button create_detail_panel create_entry create_fault_list create_info_panel create_label create_list_panel create_main_panel create_progress_bar create_suite_panel create_text create_tooltip create_window finished new output_status raw_show_fault reset_ui result_changed setup_mediator setup_ui show_fault start start_ui started stop test_started

### Constants

RED_STYLE | = | FXRGBA(0xFF,0,0,0xFF)
GREEN_STYLE | = | FXRGBA(0,0xFF,0,0xFF)

### Public Class methods

new(suite, output_level = NORMAL)

Creates a new TestRunner for running the passed suite.

[Source]

    # File test/unit/ui/fox/testrunner.rb, line 30
              def initialize(suite, output_level = NORMAL)
                if (suite.respond_to?(:suite))
                  @suite = suite.suite
                else
                  @suite = suite
                end

                @result = nil
                @red = false
              end

### Public Instance methods

add_fault(fault)

[Source]

    # File test/unit/ui/fox/testrunner.rb, line 95
              def add_fault(fault)
                if ( ! @red )
                  @test_progress_bar.barColor = RED_STYLE
                  @red = true
                end
                item = FaultListItem.new(fault)
                @fault_list.appendItem(item)
              end

attach_to_mediator()

[Source]

    # File test/unit/ui/fox/testrunner.rb, line 59
              def attach_to_mediator
                @mediator.add_listener(TestRunnerMediator::RESET, &method(:reset_ui))
                @mediator.add_listener(TestResult::FAULT, &method(:add_fault))
                @mediator.add_listener(TestResult::CHANGED, &method(:result_changed))
                @mediator.add_listener(TestRunnerMediator::STARTED, &method(:started))
                @mediator.add_listener(TestCase::STARTED, &method(:test_started))
                @mediator.add_listener(TestRunnerMediator::FINISHED, &method(:finished))
              end

clear_fault()

[Source]

    # File test/unit/ui/fox/testrunner.rb, line 112
              def clear_fault
                raw_show_fault("")
              end

create_application()

[Source]

    # File test/unit/ui/fox/testrunner.rb, line 181
              def create_application
                app = FXApp.new("TestRunner", "Test::Unit")
                app.init([])
                app
              end

create_button(parent, text, action)

[Source]

    # File test/unit/ui/fox/testrunner.rb, line 205
              def create_button(parent, text, action)
                FXButton.new(parent, text).connect(SEL_COMMAND, &action)
              end

create_detail_panel(parent)

[Source]

    # File test/unit/ui/fox/testrunner.rb, line 237
              def create_detail_panel(parent)
                FXHorizontalFrame.new(parent, LAYOUT_FILL_X | LAYOUT_FILL_Y | FRAME_SUNKEN | FRAME_THICK)
              end

create_entry(parent)

[Source]

    # File test/unit/ui/fox/testrunner.rb, line 245
              def create_entry(parent)
                entry = FXTextField.new(parent, 30, nil, 0, TEXTFIELD_NORMAL | LAYOUT_SIDE_BOTTOM | LAYOUT_FILL_X)
                entry.disable
                entry
              end

create_fault_list(parent)

[Source]

    # File test/unit/ui/fox/testrunner.rb, line 225
              def create_fault_list(parent)
                list = FXList.new(parent, 10, nil, 0, LIST_SINGLESELECT | LAYOUT_FILL_X) #, 0, 0, 0, 150)
                list.connect(SEL_COMMAND) do |sender, sel, ptr|
                  if sender.retrieveItem(sender.currentItem).selected?
                    show_fault(sender.retrieveItem(sender.currentItem).fault)
                  else
                    clear_fault
                  end
                end
                list
              end

create_info_panel(parent)

[Source]

    # File test/unit/ui/fox/testrunner.rb, line 213
              def create_info_panel(parent)
                FXMatrix.new(parent, 1, MATRIX_BY_ROWS | LAYOUT_FILL_X)
              end

create_label(parent, text)

[Source]

    # File test/unit/ui/fox/testrunner.rb, line 217
              def create_label(parent, text)
                FXLabel.new(parent, text, nil, JUSTIFY_CENTER_X | LAYOUT_FILL_COLUMN)
              end

create_list_panel(parent)

[Source]

    # File test/unit/ui/fox/testrunner.rb, line 221
              def create_list_panel(parent)
                FXHorizontalFrame.new(parent, LAYOUT_FILL_X | FRAME_SUNKEN | FRAME_THICK)
              end

create_main_panel(parent)

[Source]

    # File test/unit/ui/fox/testrunner.rb, line 195
              def create_main_panel(parent)
                panel = FXVerticalFrame.new(parent, LAYOUT_FILL_X | LAYOUT_FILL_Y)
                panel.vSpacing = 10
                panel
              end

create_progress_bar(parent)

[Source]

    # File test/unit/ui/fox/testrunner.rb, line 209
              def create_progress_bar(parent)
                FXProgressBar.new(parent, nil, 0, PROGRESSBAR_NORMAL | LAYOUT_FILL_X)
              end

create_suite_panel(parent)

[Source]

    # File test/unit/ui/fox/testrunner.rb, line 201
              def create_suite_panel(parent)
                FXHorizontalFrame.new(parent, LAYOUT_SIDE_LEFT | LAYOUT_FILL_X)
              end

create_text(parent)

[Source]

    # File test/unit/ui/fox/testrunner.rb, line 241
              def create_text(parent)
                FXText.new(parent, nil, 0, TEXT_READONLY | LAYOUT_FILL_X | LAYOUT_FILL_Y)
              end

create_tooltip(app)

[Source]

    # File test/unit/ui/fox/testrunner.rb, line 191
              def create_tooltip(app)
                FXTooltip.new(app)
              end

create_window(app)

[Source]

    # File test/unit/ui/fox/testrunner.rb, line 187
              def create_window(app)
                FXMainWindow.new(app, "Test::Unit TestRunner", nil, nil, DECOR_ALL, 0, 0, 450)
              end

finished(elapsed_time)

[Source]

    # File test/unit/ui/fox/testrunner.rb, line 138
              def finished(elapsed_time)
                output_status("Finished in #{elapsed_time} seconds")
              end

output_status(string)

[Source]

    # File test/unit/ui/fox/testrunner.rb, line 142
              def output_status(string)
                @status_entry.text = string
                @status_entry.repaint
              end

raw_show_fault(string)

[Source]

    # File test/unit/ui/fox/testrunner.rb, line 108
              def raw_show_fault(string)
                @detail_text.setText(string)
              end

reset_ui(count)

[Source]

    # File test/unit/ui/fox/testrunner.rb, line 81
              def reset_ui(count)
                @test_progress_bar.barColor = GREEN_STYLE
                @test_progress_bar.total = count
                @test_progress_bar.progress = 0
                @red = false

                @test_count_label.text = "0"
                @assertion_count_label.text = "0"
                @failure_count_label.text = "0"
                @error_count_label.text = "0"

                @fault_list.clearItems
              end

result_changed(result)

[Source]

    # File test/unit/ui/fox/testrunner.rb, line 116
              def result_changed(result)
                @test_progress_bar.progress = result.run_count

                @test_count_label.text = result.run_count.to_s
                @assertion_count_label.text = result.assertion_count.to_s
                @failure_count_label.text = result.failure_count.to_s
                @error_count_label.text = result.error_count.to_s

                 # repaint now!
                 @info_panel.repaint
                 @application.flush
              end

setup_mediator()

[Source]

    # File test/unit/ui/fox/testrunner.rb, line 50
              def setup_mediator
                @mediator = TestRunnerMediator.new(@suite)
                suite_name = @suite.to_s
                if ( @suite.kind_of?(Module) )
                  suite_name = @suite.name
                end
                @suite_name_entry.text = suite_name
              end

setup_ui()

[Source]

    # File test/unit/ui/fox/testrunner.rb, line 147
              def setup_ui
                @application = create_application
                create_tooltip(@application)

                @window = create_window(@application)

                @status_entry = create_entry(@window)

                main_panel = create_main_panel(@window)

                suite_panel = create_suite_panel(main_panel)
                create_label(suite_panel, "Suite:")
                @suite_name_entry = create_entry(suite_panel)
                create_button(suite_panel, "&Run\tRun the current suite", proc { @mediator.run_suite })

                @test_progress_bar = create_progress_bar(main_panel)

                @info_panel = create_info_panel(main_panel)
                create_label(@info_panel, "Tests:")
                @test_count_label = create_label(@info_panel, "0")
                create_label(@info_panel, "Assertions:")
                @assertion_count_label = create_label(@info_panel, "0")
                create_label(@info_panel, "Failures:")
                @failure_count_label = create_label(@info_panel, "0")
                create_label(@info_panel, "Errors:")
                @error_count_label = create_label(@info_panel, "0")

                list_panel = create_list_panel(main_panel)
                @fault_list = create_fault_list(list_panel)

                detail_panel = create_detail_panel(main_panel)
                @detail_text = create_text(detail_panel)
              end

show_fault(fault)

[Source]

    # File test/unit/ui/fox/testrunner.rb, line 104
              def show_fault(fault)
                raw_show_fault(fault.long_display)
              end

start()

Begins the test run.

[Source]

    # File test/unit/ui/fox/testrunner.rb, line 42
              def start
                setup_ui
                setup_mediator
                attach_to_mediator
                start_ui
                @result
              end

start_ui()

[Source]

    # File test/unit/ui/fox/testrunner.rb, line 68
              def start_ui
                @application.create
                @window.show(PLACEMENT_SCREEN)
                @application.addTimeout(1) do
                  @mediator.run_suite
                end
                @application.run
              end

started(result)

[Source]

    # File test/unit/ui/fox/testrunner.rb, line 129
              def started(result)
                @result = result
                output_status("Started...")
              end

stop()

[Source]

    # File test/unit/ui/fox/testrunner.rb, line 77
              def stop
                @application.exit(0)
              end

test_started(test_name)

[Source]

    # File test/unit/ui/fox/testrunner.rb, line 134
              def test_started(test_name)
                output_status("Running #{test_name}...")
              end

[Validate]