# Re: Test::Unit run order

**URL:** <https://www.ruby-forum.com/t/re-test-unit-run-order/172193>\
**Category:** Ruby\
**Created:** [July 16, 2009, 2:58pm UTC](https://www.ruby-forum.com/t/re-test-unit-run-order/172193 "2009-07-16T14:58:14Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![dawillis](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ebca7d/32.png) [@dawillis](https://www.ruby-forum.com/u/dawillis)\
**Post date:** [July 16, 2009, 2:58pm UTC](https://www.ruby-forum.com/t/re-test-unit-run-order/172193/1 "2009-07-16T14:58:14Z")

</div>

On Jul 15, 2009, at 1:33 PM, James C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

2009/7/15 Dylan [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

Hey there! I had a question about the order tests are run in  
Test::Unit. I have a class with about 10 tests and I’d like to be able  
to better control the order they run in. Right now they just run  
alphabetically, and I could just add prefixes to my test names, but  
I’m likely not going to be the one updating this code in the future  
and I’d like to keep it as straightforward and simple as possible  
(i.e. not end up with test\_admintests\_part1\_login as a test name). I’m  
keeping them all in one class because I’m using CI\_reporter to  
generate the XML results and I’d like it to be in one file. Is there  
any way to change the order individual tests run, or is there a way to  
have CI\_reporter create only 1 XML file for multiple test suites. I’ve  
looked around quite a bit for answers to either of these questions but  
have so far found nothing (although it’s a distinct possibility that I  
just totally missed it an need a smack on the head). 🙂 Thank you very  
much!

I can’t speak about your XML stuff, but I’m pretty sure the  
Test::Unit::TestCase.suite method sorts the tests by name so you can’t  
change the order. Your options are:

1. Construct the test suite yourself rather than relying on the above  
method  
to do it for you. You’ll have to dig around in Test::Unit’s source to  
figure  
out how to run tests without using AutoRunner.

2. Take a look at some of the code in test/unit/ui and look at the  
logging  
events that tests fire. These should allow you to collect event data and  
reorder it however you like before creating a report.

Both will require some inspecting of Test::Unit’s source, but I’m sure  
others have better suggestions. Test::Unit’s README is pretty good if  
you  
need to know some details on its internals, e.g. how TestCases are  
converted  
to suites and run.

I believe you can number tests.  
e.g. test\_01\_blah\_etc, test\_02\_blah  
I can’t verify at the moment if this actually works or is just alpha  
order. I.e. That test\_11\_blah will be where you expect it
