On 7/18/07, aidy.lewis / googlemail.com <aidy.lewis / googlemail.com> wrote:
> I have been running the Test_Suite_1.rb from a batch file
>
> system "test_suite.bat"
> system "test_suite.bat"
>
> But I a unable to keep the value of @@j (in test_data.rb) between the
> system calls, so as to use the next set off data in the array.
>
> Thanks
>
> Aidy

Hi,

I have looked at the code, but I haven't found a nice solution :(
That said, you can run your class by

require 'test/unit/testsuite'
require 'test/unit/ui/console/testrunner'

class TS_MyTests
        def self.suite
                suite = Test::Unit::TestSuite.new
                suite << Test_Suite_1.suite
                suite << Test_Suite_1.suite
                return suite
        end
end

Test::Unit::UI::Console::TestRunner.run(TS_MyTests)

It won't help you as @@test is set only once - when the class is defined.

I wonder why do you use Test::Unit, when you barely use its features
(by that I mean especially no asserts in the code). If it is indeed
the case (no hidden asserts somewhere in the unpublished code), it
might be easier to run your cases by your code.

Another way how to solve it would be to create custom TestSuite, that
would set the data and call the test case.

class RepeatingTestSuite < Test::Unit::TestSuite
        def initialize(count=1, name="Unnamed TestSuite")
                super(name)
                @count = count
        end

        def run(result, &progress_block)
                # set your data here
                @count.times do
                        super
                end
        end

        def size
                return @count * super
        end
end

class TS_MyTests
        def self.suite
                suite = RepeatingTestSuite.new(2)
                suite << Test_Suite_1.suite
                return suite
        end
end

Another thing that came to my mind is that you can solve your
xml-saving problem by creating a custom runner, that will store the
results into xml instead of printing to console.

Then, you might consider storing your data directly in an array of
hashes, or in the separate YAML file, though I don't know why you did
this way - where the data comes from etc.
Now, you have a little bug, when you advance @@j by1 when you should by 3

Finally, consider declaring creating object for one data set, and a
special container for
all the sets. That should clear your design at least bit.

If you add "each" method to your container you can write your run method as:

        def run(result, &progress_block)
                container.each do |data|
                        $current_data = data
                        super
                end
        end

Global variable is a dirty hack and should be avoided, but I cannot
think of a better solution now.

BTW. using a lot of @@ class variables is a mark of a bad design
IMHOI... not always, but usually. Maybe splitting into more classes
will help.

And have a look at test/unit sources if you haven't done
already...there's much more info that in the docs. Most of the code is
easy, except that throw/catch part in the TestCase ;-)

HTH,

Jano