转:whoami
Watir自动测试应用(4):关于Ruby的自动测试框架
对于TestCase的书写如下:- require 'test/unit' #引用的自动测试类库
- #必须TestCase必须继承于Test::Unit::TestCase
- class TC_MyTest< Test::Unit::TestCase
- def setup
- #添加每个测试test预设环境参数
- #注意这里指的是每个test不是TestCase
- end
- def teardown
- #添加每个测试test清除环境参数
- end
- def test_case1
- #判断失败
- assert(false, 'Assertion was false.')
- end
- def test_case2
- #判断成功
- assert(true, 'Assertion was false.')
- end
- end
复制代码 调用如下:
使用TestSuite- require 'test/unit/testsuite'
- require 'tc_myfirsttests'
- class TS_MyTests
- def self.suite
- suite = Test::Unit::TestSuite.new
- suite << TC_MyTest.suite
- return suite
- end
- end
- Test::Unit::UI::Console::TestRunner.run(TS_MyTests)
复制代码 如果也可以直接调用:- require 'test/unit/ui/console/testrunner'
- Test::Unit::UI::Console::TestRunner.run(TC_MyTest)
复制代码 也可以使用命令行执行单一test:- Ruby tc_myfirsttests.rb --name test_case1
复制代码 当然使用ecplise也是可以运行滴。。。 |