# Test::Unit - Ruby Unit Testing Framework Questions

**URL:** <https://www.ruby-forum.com/t/test-unit-ruby-unit-testing-framework-questions/177716>\
**Category:** Ruby\
**Created:** [October 22, 2009, 4:02pm UTC](https://www.ruby-forum.com/t/test-unit-ruby-unit-testing-framework-questions/177716 "2009-10-22T16:02:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![musty](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/77aa72/32.png) [@musty](https://www.ruby-forum.com/u/musty)\
**Post date:** [October 22, 2009, 4:02pm UTC](https://www.ruby-forum.com/t/test-unit-ruby-unit-testing-framework-questions/177716/1 "2009-10-22T16:02:10Z")

</div>

Recently, we collected several (29) Selenium Ruby scripts and put them  
into a unit test that runs whenever thereâ€™s a build of our product.  
Thatâ€™s been reasonably successful, but our developers would like more.  
Specifically, they would like us to include asserts inside of our  
scripts.

I see two challenges to this. First, I need guidance on when to code an  
assertion. I have some ideas, but like all the open source  
documentation I see so far, the emphasis seems to be on syntax rather  
than semantics.

Second, Iâ€™m a little concerned about inconvenience when Iâ€™m debugging an  
individual test in the unit test package. The following are real code  
examples from my environment.

Run the campaign canvas script under IE:

Today:  
driver $ ca  
(11 characters)

With Test::Unit:  
selenium\_tests.rb --name test\_create\_canvas  
(45 characters, and I cannot pick the browser)

Driver.rb invokes the browser of choice ($ in this case, the default is  
Firefox if it cannot make out what you asked for), then runs the chosen  
script (ca, chosen out of an if/elsif stack with case insensitivity and  
matching to the string supplied, even if itâ€™s abbreviated).

With Test::Unit: I lose the ability to pick browser and have to do a  
lot more typing to pick a test, and that typing has to be spot on. I  
can help the latter problem with some careful re-naming.

I had thought to turn driver into a unit test by surrounding it with the  
basic code, but I cannot figure out how to get to the ARGV array once I  
do that, so I cannot read the command line.

* * *

Bill M. | Test Automation | office: (703) 584-2768  
| fax: (703) 584-2751  
removed\_email\_address@domain.invalid | Eloqua [www.eloqua.com](http://www.eloqua.com) | 1921 Gallows Road,  
Suite 250, Vienna, VA 22182

---

<div class="post-metadata">

**Author:** ![musty](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/77aa72/32.png) [@musty](https://www.ruby-forum.com/u/musty)\
**Post date:** [December 11, 2009, 3:58pm UTC](https://www.ruby-forum.com/t/test-unit-ruby-unit-testing-framework-questions/177716/2 "2009-12-11T15:58:57Z")

</div>

Hello Bill,

On Thu, Oct 22, 2009 at 9:02 AM, Bill M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> With Test::Unit: Â I lose the ability to pick browser and have to do a  
> lot more typing to pick a test, and that typing has to be spot on. Â I  
> can help the latter problem with some careful re-naming.
> 
> I had thought to turn driver into a unit test by surrounding it with the  
> basic code, but I cannot figure out how to get to the ARGV array once I  
> do that, so I cannot read the command line.

I am also trying to get more familiar with Test::Unit. In my case I  
have some scripts that operate on a sqlite3 database. Since a sqlite3  
database is just a file with some arbitrary name, I needed to be able  
to pass in the name of the file to the testing script. The solution I  
used was this construct:

`
require 'test/unit'
require 'sqlite3'
require 'lib/sample.rb'
$dbfile = ARGV[0] || “sample.db”
exit unless File.exist?($dbfile)
`

`class TestSample < Test::Unit::TestCase
…
`

In this way I was able to test my sample.rb code using the foo.db like  
this:

$ ./tests/test\_sample.rb foo.db

and if I wanted to test it with the bar.db, I could do this:

$ ./tests/test\_sample.rb bar.db

And if I don’t specify a file, it defaults to “sample.db”.

I don’t know if that is the “right way” to do it, but it’s working for  
me thus far.

Let us know what you’ve tried and what works (and what doesn’t) for you.

Regards,

- Robert

---

<div class="post-metadata">

**Author:** ![musty](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/77aa72/32.png) [@musty](https://www.ruby-forum.com/u/musty)\
**Post date:** [December 11, 2009, 4:21pm UTC](https://www.ruby-forum.com/t/test-unit-ruby-unit-testing-framework-questions/177716/3 "2009-12-11T16:21:01Z")

</div>

Bill M. wrote:

> Recently, we collected several (29) Selenium Ruby scripts and put them  
> into a unit test that runs whenever thereâ€™s a build of our product.  
> Thatâ€™s been reasonably successful, but our developers would like more.  
> Specifically, they would like us to include asserts inside of our  
> scripts.  
> […]

You probably want to use Cucumber and Webrat. I would also recommend  
considering RSpec instead of Test::Unit.

Best,  
–Â  
MarnenÂ Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid
