A simpler method is simply to embed line numbers in your test names...
def test_001_something
end
def test_002_another_thing
end
Or, you can simply remove the code that explicitly puts the tests in
alphabetical order.
Here's the original code:
# Rolls up all of the test* methods in the fixture into
# one suite, creating a new instance of the fixture for
# each method.
def self.suite
method_names = public_instance_methods(true)
tests = method_names.delete_if {|method_name| method_name !~ /^test./}
suite = TestSuite.new(name)
tests.sort.each do
|test|
catch(:invalid_test) do
suite << new(test)
end
end
if (suite.empty?)
catch(:invalid_test) do
suite << new(:default_test)
end
end
return suite
end
Here it is without the sorting behavior:
# Rolls up all of the test* methods in the fixture into
# one suite, creating a new instance of the fixture for
# each method.
def self.suite
method_names = public_instance_methods(true)
tests = method_names.delete_if {|method_name| method_name !~ /^test./}
suite = TestSuite.new(name)
tests.each do ### change made here
|test|
catch(:invalid_test) do
suite << new(test)
end
end
if (suite.empty?)
catch(:invalid_test) do
suite << new(:default_test)
end
end
return suite
end
I haven't tested this change, but i think this will give you the tests in
the order you want.
At 06:38 PM 8/30/2005, Paul Rogers wrote:
Here is some code that runs tests in source code order. I pretty certain
Bret posted how to do this ( by overriding the suite method) but he didnt
provide any code.
This only works if there is one class that does tests in the file, but Im
sure someone can figure out how to fix that
#
# Example of how to override the suite method of Testcase to run tests in
source order
#
# Only works if there is one class that runs tests
require 'test/unit'
module Test
module Unit
class TestCase
def self.suite
lines = IO.readlines(__FILE__)
tests = lines.grep(/^ *(def test)/){ |line|
line.strip.gsub('def ' , '') }
suite = TestSuite.new(name)
tests.each do |this_test|
puts "Adding test " + this_test
catch(:invalid_test) do
suite << new(this_test)
end
end
if (suite.empty?)
catch(:invalid_test) do
suite << new(:default_test)
end
end
return suite
end
end
end
end
class Tester <Test::Unit::TestCase
def test_020
puts "020"
end
def test_030
puts "030"
end
def test_100
puts "100"
end
def test_010
puts "010"
end
end
_______________________________________________
Wtr-general mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/wtr-general
_____________________
Bret Pettichord
www.pettichord.com
_______________________________________________
Wtr-general mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/wtr-general