Starting unit testing with Rake?

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

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 Development 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...

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 Development 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 <-- NOT a blog!!

Thanks for the help.

Jeff

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!

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

Test::Unit.run = true

:slight_smile: 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