# Starting unit testing with Rake?

**URL:** <https://www.ruby-forum.com/t/starting-unit-testing-with-rake/83548>\
**Category:** Rails\
**Created:** [January 27, 2007, 2:35am UTC](https://www.ruby-forum.com/t/starting-unit-testing-with-rake/83548 "2007-01-27T02:35:38Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jeff](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e19b73/32.png) [@jeff](https://www.ruby-forum.com/u/jeff)\
**Post date:** [January 27, 2007, 2:35am UTC](https://www.ruby-forum.com/t/starting-unit-testing-with-rake/83548/1 "2007-01-27T02:35:38Z")

</div>

I feel silly for asking this, but how do I start unit testing with  
Rake?

I’m just getting started setting up unit tests and learning about it,  
but my googling hasn’t turned up any straightforward “getting started”  
tutorials for running my unit tests with Rake.

I’ve set up a few simple unit tests to start with and I’m not sure how  
to actually run them. I see reference to just running “rake” or “rake  
test:units” but those don’t seem to run my tests. What more do I need  
to do?

Thanks in advance,  
Jeff

---

<div class="post-metadata">

**Author:** ![jeff](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e19b73/32.png) [@jeff](https://www.ruby-forum.com/u/jeff)\
**Post date:** [January 27, 2007, 3:13am UTC](https://www.ruby-forum.com/t/starting-unit-testing-with-rake/83548/2 "2007-01-27T03:13:41Z")

</div>

progressions wrote:

> I’ve set up a few simple unit tests to start with and I’m not sure how  
> to actually run them. I see reference to just running “rake” or “rake  
> test:units” but those don’t seem to run my tests. What more do I need  
> to do?

Post some code; you might have the test declared wrong.

rake alone will run rake test

Where are your unit tests? Are they in the test/\*/ folders where the  
rake test task expects them?

Would this run them?

ruby test/unit/my\_model\_test.rb

The Agile Web D. with Rails book laid all this out, if I  
recall correctly. But that was a long, long time ago in Rails-time.  
Last month, I think…

–  
Phlip  
[http://c2.com/cgi/wiki?ZeekLand](http://c2.com/cgi/wiki?ZeekLand) ← NOT a blog!!

---

<div class="post-metadata">

**Author:** ![jeff](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e19b73/32.png) [@jeff](https://www.ruby-forum.com/u/jeff)\
**Post date:** [January 27, 2007, 4:45am UTC](https://www.ruby-forum.com/t/starting-unit-testing-with-rake/83548/3 "2007-01-27T04:45:48Z")

</div>

On Jan 26, 8:13 pm, Phlip [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> progressions wrote:
> 
> > I’ve set up a few simple unit tests to start with and I’m not sure how  
> > to actually run them. I see reference to just running “rake” or “rake  
> > test:units” but those don’t seem to run my tests. What more do I need  
> > to do?Post some code; you might have the test declared wrong.
> 
> rake alone will run rake test
> 
> Where are your unit tests? Are they in the test/\*/ folders where the  
> rake test task expects them?

I haven’t done much of anything to the tests. They’re right where they  
should. I’m trying to run test/unit/comic\_test.rb (from the model  
“comic”) and it does nothing.

> Would this run them?
> 
> ruby test/unit/my\_model\_test.rb

This doesn’t do anything:

C:\rails\comics\trunk\>ruby test/unit/comic\_test.rb

C:\rails\comics\trunk\>ruby test/unit/comic\_test.rb

C:\rails\comics\trunk\>

…I tried putting a “puts” statement in the comic\_test.rb file to  
verify that it would run at all, and it does. But the testing engine  
doesn’t seem to get invoked at all.

> The Agile Web D. with Rails book laid all this out, if I  
> recall correctly. But that was a long, long time ago in Rails-time.  
> Last month, I think…

I’m definitely planning on getting the second edition when I can, but I  
don’t have it yet.

> –  
> Phlip  
> [http://c2.com/cgi/wiki?ZeekLand](http://c2.com/cgi/wiki?ZeekLand) ← NOT a blog!!

Thanks for the help.

Jeff

---

<div class="post-metadata">

**Author:** ![jeff](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e19b73/32.png) [@jeff](https://www.ruby-forum.com/u/jeff)\
**Post date:** [January 27, 2007, 5:58am UTC](https://www.ruby-forum.com/t/starting-unit-testing-with-rake/83548/4 "2007-01-27T05:58:51Z")

</div>

Hm. I’m guessing this line I put in my environment.rb might have  
something to do with it?

Test::Unit.run = true

🙂 Was advised to put that in because it was running tests on my  
production server and forgot about it til now. Sorry about that!

Jeff

---

<div class="post-metadata">

**Author:** ![jeff](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e19b73/32.png) [@jeff](https://www.ruby-forum.com/u/jeff)\
**Post date:** [January 27, 2007, 5:17am UTC](https://www.ruby-forum.com/t/starting-unit-testing-with-rake/83548/5 "2007-01-27T05:17:49Z")

</div>

progressions wrote:

> This doesn’t do anything:
> 
> C:\rails\comics\trunk\>ruby test/unit/comic\_test.rb
> 
> C:\rails\comics\trunk\>ruby test/unit/comic\_test.rb

Start with the obvious stuff. Your 'puter is turned on, and ‘ruby -v’  
prints  
Ruby’s version, right?

Next, the first 5 lines of your test should look like this:

require File.dirname( **FILE** ) + ‘/…/test\_helper’

class ChatTest \< Test::Rails::TestCase

def test\_something  
assert false  
end

Tests work by inheriting a class that registers each of its children in  
a  
test runner. You might try ‘Test::Unit’ or ‘Test::Rails’ there - I seem  
to  
recall the ‘Rails’ might be from one of my plugins.

If that doesn’t work, write a new source file with only this in it:

require ‘test/unit’

class TestAnything \< Test::Unit::TestCase # “it has come to this”  
–Poo…  
def test\_anything  
assert false  
end  
end

If you can’t get that working, post to the Ruby newsgroup, and work your  
way  
back to Rails!

–  
Phlip  
[Redirecting...](http://www.greencheese.us/ZeekLand) ← NOT a blog!!!
