# ARGV and unit tests: different problem

**URL:** <https://www.ruby-forum.com/t/argv-and-unit-tests-different-problem/92215>\
**Category:** Ruby\
**Created:** [April 17, 2007, 6:11am UTC](https://www.ruby-forum.com/t/argv-and-unit-tests-different-problem/92215 "2007-04-17T06:11:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![yuricake](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/71c47a/32.png) [@yuricake](https://www.ruby-forum.com/u/yuricake)\
**Post date:** [April 17, 2007, 6:11am UTC](https://www.ruby-forum.com/t/argv-and-unit-tests-different-problem/92215/1 "2007-04-17T06:11:13Z")

</div>

Hello,

I am experiencing the following strange problem (this is present in  
ruby versions 1.8.5 and 1.8.6): if I rely on the test suites to be run  
automatically, the ARGV variable is no longer present inside the  
testcases. If I run the test suites explicitly, the ARGV variable  
remains the same. I do not understand if this is a bug or if I am  
misunderstanding what the automatic test runner does.

The two code snippets below illustrate what I mean:

require “test/unit”  
require “pp”  
class TC\_Mysql \< Test::Unit::TestCase  
def setup()  
puts “inside”  
pp ARGV  
end  
def test\_one()  
assert\_equal(1, 1)  
end  
end  
puts “outside”  
pp ARGV

if I run the above code with:

ruby test.rb Yo

I get the following output:

outside  
[“yo”]  
Loaded suite args  
Started  
inside  
[]

However, if I modify the code snippet to:

require “test/unit”  
require “pp”  
class TC\_Mysql \< Test::Unit::TestCase  
def setup()  
puts “inside”  
pp ARGV  
end  
def test\_one()  
assert\_equal(1, 1)  
end  
end  
puts “outside”  
pp ARGV  
require ‘test/unit/ui/console/testrunner’  
Test::Unit::UI::Console::TestRunner.run(TC\_Mysql)

running it with

ruby test.rb Yo

I get the following output:

outside  
[“yo”]  
Loaded suite TC\_Mysql  
Started  
inside  
[“yo”]

---

<div class="post-metadata">

**Author:** ![yuricake](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/71c47a/32.png) [@yuricake](https://www.ruby-forum.com/u/yuricake)\
**Post date:** [April 17, 2007, 10:24am UTC](https://www.ruby-forum.com/t/argv-and-unit-tests-different-problem/92215/2 "2007-04-17T10:24:41Z")

</div>

On 4/17/07, yuricake [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> end  
> [“yo”]  
> def setup()  
> Test::Unit::UI::Console::TestRunner.run(TC\_Mysql)  
> Started  
> inside  
> [“yo”]

Hi,

your problem is caused by the fact that autorunner responds to some  
command line arguments (run your suite with --help for the list). if  
you want to pass arguments to your tests, use – as a delimiter  
between testrunner’s and your arguments.

For very detailed info read lib/test/unit/autorunner.rb.

J.
