# Test unit with ARGV input

**URL:** <https://www.ruby-forum.com/t/test-unit-with-argv-input/55787>\
**Category:** Ruby\
**Created:** [March 23, 2006, 9:29pm UTC](https://www.ruby-forum.com/t/test-unit-with-argv-input/55787 "2006-03-23T21:29:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rtilley](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ce7236/32.png) [@rtilley](https://www.ruby-forum.com/u/rtilley)\
**Post date:** [March 23, 2006, 9:29pm UTC](https://www.ruby-forum.com/t/test-unit-with-argv-input/55787/1 "2006-03-23T21:29:00Z")

</div>

I can’t get test/unit to work with command line scripts that take user  
input via ARGV. Any tips on this? I continually get ‘initialize’: wrong  
number of arguments (0 for 1) (ArgumentError) that go back to my  
initialize method which is simply this:

def initialize  
super  
end

---

<div class="post-metadata">

**Author:** ![rtilley](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ce7236/32.png) [@rtilley](https://www.ruby-forum.com/u/rtilley)\
**Post date:** [March 23, 2006, 9:42pm UTC](https://www.ruby-forum.com/t/test-unit-with-argv-input/55787/2 "2006-03-23T21:42:34Z")

</div>

On Fri, 2006-03-24 at 05:28 +0900, rtilley wrote:

> I can’t get test/unit to work with command line scripts that take user  
> input via ARGV. Any tips on this? I continually get ‘initialize’: wrong  
> number of arguments (0 for 1) (ArgumentError) that go back to my  
> initialize method which is simply this:
> 
> def initialize  
> super  
> end

(I assume this is in a testcase class?)

Test::Unit::TestCase#initialize requires one argument, the name of the  
test being run. For each test method, a new instance is used. You would  
need to do:

def initialize(name)  
super(name)  
end

You could omit (name) from the super call (it assumes the same arguments  
anyway) but I prefer to be explicit.

All that said, you should generally handle custom initialization for  
your tests from the ‘setup’ method, which is called before each test is  
run.

As a general tip, whenever you have a situation like this you can  
temporarily do:

def initialize(\*args)  
p args  
super(\*args)  
end

To see what you’re supposed to be dealing with.

---

<div class="post-metadata">

**Author:** ![rtilley](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ce7236/32.png) [@rtilley](https://www.ruby-forum.com/u/rtilley)\
**Post date:** [March 23, 2006, 9:44pm UTC](https://www.ruby-forum.com/t/test-unit-with-argv-input/55787/3 "2006-03-23T21:44:03Z")

</div>

Not sure from what you gave but are you calling TestCase’s initialize  
when you call super? Because that takes one argument which is the name  
of the method being tested. (I could be completely wrong here i  
haven’t tried too many off the wall things with test/unit)

---

<div class="post-metadata">

**Author:** ![rtilley](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ce7236/32.png) [@rtilley](https://www.ruby-forum.com/u/rtilley)\
**Post date:** [March 23, 2006, 9:54pm UTC](https://www.ruby-forum.com/t/test-unit-with-argv-input/55787/4 "2006-03-23T21:54:00Z")

</div>

Ross B. wrote:

> All that said, you should generally handle custom initialization for  
> your tests from the ‘setup’ method, which is called before each test is  
> run.

OK, I got it working… I’m new to test unit… this was my first go at  
it. It’s working now. Thank you both for the info!
