# Test unit with ARGV input

**URL:** <https://rubytalk.org/t/test-unit-with-argv-input/26048>\
**Category:** ruby-talk\
**Created:** [23 March 2006 20:28 UTC](https://rubytalk.org/t/test-unit-with-argv-input/26048 "2006-03-23T20:28:51Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Brad5](https://avatars.discourse-cdn.com/v4/letter/b/9dc877/32.png) [@Brad5](https://rubytalk.org/u/Brad5)\
**Post date:** [23 March 2006 20:28 UTC](https://rubytalk.org/t/test-unit-with-argv-input/26048/1 "2006-03-23T20:28:51Z")

</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  
&nbsp;&nbsp;&nbsp;super  
end

---

<div class="post-metadata">

**Author:** ![Ross\_Bamford4](https://avatars.discourse-cdn.com/v4/letter/r/ea666f/32.png) [@Ross\_Bamford4](https://rubytalk.org/u/Ross_Bamford4)\
**Post date:** [23 March 2006 20:42 UTC](https://rubytalk.org/t/test-unit-with-argv-input/26048/2 "2006-03-23T20:42:30Z")

</div>

(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)  
&nbsp;&nbsp;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)  
&nbsp;&nbsp;p args  
&nbsp;&nbsp;super(\*args)  
end

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

> **···**
>
> 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  
> > &nbsp;&nbsp;&nbsp;super  
> > end
> 
> --  
> Ross Bamford - rosco@roscopeco.REMOVE.co.uk

---

<div class="post-metadata">

**Author:** ![Geoff4](https://avatars.discourse-cdn.com/v4/letter/g/bc8723/32.png) [@Geoff4](https://rubytalk.org/u/Geoff4)\
**Post date:** [23 March 2006 20:43 UTC](https://rubytalk.org/t/test-unit-with-argv-input/26048/3 "2006-03-23T20:43:51Z")

</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:** ![Brad5](https://avatars.discourse-cdn.com/v4/letter/b/9dc877/32.png) [@Brad5](https://rubytalk.org/u/Brad5)\
**Post date:** [23 March 2006 20:53 UTC](https://rubytalk.org/t/test-unit-with-argv-input/26048/4 "2006-03-23T20:53:52Z")

</div>

Ross Bamford wrote:

> 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)  
> &nbsp;&nbsp;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.

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!
