Thursday, October 28, 2010

Test Unit

Test::Unit is a library of Ruby (just like Watir)

It is not technically part of Watir…however it is used regularly to structure tests.

To use Test::Unit in your scripts you ‘require’ it just as you do watir

require ‘test/unit’
require ‘watir’

Test::Unit is a way to organize your code into “tests”

Test::Unit has built in methods called “assertions” that help your tests with validation.

assert(browser.link(:text, “Click Here”).exists?)

The above statement will return a TRUE or FALSE indicating a pass or fail in your test.

Below is the basic code structure of a class in Test unit

require 'test/unit’

    class TC_MyTest < Test::Unit::TestCase
    include Watir

    def setup        #optional
    end            #optional
    def teardown      #optional
    end             #optional

        def test_pass
            assert(something.exists?)
        end
    end 


No comments:

Post a Comment