Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class MyTest < Test::Unit::TestCase
- def setup
- end
- def test_1
- end
- def test_1
- end
- end
- require 'test/unit'
- require 'test/unit/ui/console/testrunner'
- class TestDecorator < Test::Unit::TestSuite
- def initialize(test_case_class)
- super
- self << test_case_class.suite
- end
- def run(result, &progress_block)
- setup_suite
- begin
- super(result, &progress_block)
- ensure
- tear_down_suite
- end
- end
- end
- class MyTestCase < Test::Unit::TestCase
- def test_1
- puts "test_1"
- assert_equal(1, 1)
- end
- def test_2
- puts "test_2"
- assert_equal(2, 2)
- end
- end
- class MySuite < TestDecorator
- def setup_suite
- puts "setup_suite"
- end
- def tear_down_suite
- puts "tear_down_suite"
- end
- end
- Test::Unit::UI::Console::TestRunner.run(MySuite.new(MyTestCase))
- require 'test/unit'
- require 'test/unit/ui/console/testrunner'
- class TestDecorator < Test::Unit::TestSuite
- def initialize(test_case_class)
- super
- self << test_case_class.suite
- end
- def run(result, &progress_block)
- setup_suite
- begin
- super(result, &progress_block)
- ensure
- tear_down_suite
- end
- end
- end
- class MyTestCase < Test::Unit::TestCase
- def test_1
- puts "test_1"
- assert_equal(1, 1)
- end
- def test_2
- puts "test_2"
- assert_equal(2, 2)
- end
- end
- class MySuite < TestDecorator
- def setup_suite
- puts "setup_suite"
- end
- def tear_down_suite
- puts "tear_down_suite"
- end
- end
- class AnotherTestCase < Test::Unit::TestCase
- def test_a
- puts "test_a"
- assert_equal("a", "a")
- end
- end
- class Tests
- def self.suite
- suite = Test::Unit::TestSuite.new
- suite << MySuite.new(MyTestCase)
- suite << AnotherTestCase.suite
- suite
- end
- end
- Test::Unit::UI::Console::TestRunner.run(Tests.suite)
- describe "Some Feature" do
- before :each do
- # this code runs once per-test
- end
- before :all do
- # this code runs once before all the tests
- end
- it "should do something useful, rather than just being called test1" do
- # el code here
- end
- end
- class MyTest < Test::Unit::TestCase
- class << self
- def startup
- puts 'runs only once at start'
- end
- def shutdown
- puts 'runs only once at end'
- end
- end
- def setup
- puts 'runs before each test'
- end
- def teardown
- puts 'runs after each test'
- end
- def test_stuff
- assert(true)
- end
- end
- def self.suite
- mysuite = super
- def mysuite.run(*args)
- MyTest.startup()
- super
- MyTest.shutdown()
- end
- mysuite
- end
- class MyTest < Test::Unit::TestCase
- class << self
- def startup
- puts 'runs only once at start'
- end
- def shutdown
- puts 'runs only once at end'
- end
- def suite
- mysuite = super
- def mysuite.run(*args)
- MyTest.startup()
- super
- MyTest.shutdown()
- end
- mysuite
- end
- end
- def setup
- puts 'runs before each test'
- end
- def teardown
- puts 'runs after each test'
- end
- def test_stuff
- assert(true)
- end
- end
- class ImprovedUnitTestCase < Test::Unit::TestCase
- cattr_accessor :expected_test_count
- def self.global_setup; end
- def self.global_teardown; end
- def teardown
- if((self.class.expected_test_count-=1) == 0)
- self.class.global_teardown
- end
- end
- def setup
- cls = self.class
- if(not cls.expected_test_count)
- cls.expected_test_count = (cls.instance_methods.reject{|method| method[0..3] != 'test'}).length
- cls.global_setup
- end
- end
- end
- class TestSomething < ImprovedUnitTestCase
- def self.global_setup
- puts 'global_setup is only run once at the beginning'
- end
- def self.global_teardown
- puts 'global_teardown is only run once at the end'
- end
- def test_1
- end
- def test_2
- end
- end
- require 'test/unit'
- require 'setuponce'
- class MyTest < Test::Unit::TestCase
- include SetupOnce
- def self.setup_once
- puts "doing one-time setup"
- end
- def self.teardown_once
- puts "doing one-time teardown"
- end
- end
- require 'mixin_class_methods' # see footnote 1
- module SetupOnce
- mixin_class_methods
- define_class_methods do
- def setup_once; end
- def teardown_once; end
- def suite
- mySuite = super
- def mySuite.run(*args)
- @name.to_class.setup_once
- super(*args)
- @name.to_class.teardown_once
- end
- return mySuite
- end
- end
- end
- # See footnote 2
- class String
- def to_class
- split('::').inject(Kernel) {
- |scope, const_name|
- scope.const_get(const_name)
- }
- end
- end
- class MyTests < Test::Unit::TestCase
- def test_AASetup # I have a few tests that start with "A", but I doubt any will start with "Aardvark" or "Aargh!"
- #Run setup code
- end
- def MoreTests
- end
- def test_ZTeardown
- #Run teardown code
- end
- class TC_001 << Test::Unit::TestCase
- def setup
- # do stuff once
- end
- def testSuite
- falseArguments()
- arguments()
- end
- def falseArguments
- # do stuff
- end
- def arguments
- # do stuff
- end
- end
Add Comment
Please, Sign In to add comment