Defining fixtures in Unit Tests necessary?


#1

Just sinking my teeth into tests and the going is tough.

Is it necessary to define fixtures in my test file
(‘fixtures :users’)?

My test are working with the definition, but I decided to debug and
checked for the fixtures existence even without the definition and all
of them had been loaded. So what’s the purpose of the declaration?


#2

Phlip,

Well said. Hadn’t thought of that possibility, that by declaring the
fixtures, it would reload them. Smart and makes sense.

Thanks!!


#3

yachtman wrote:

Just sinking my teeth into tests and the going is tough.

Not as tough as debugging all night before a release. Stick with TDD and
you
will never look back!

Is it necessary to define fixtures in my test file
(‘fixtures :users’)?

My test are working with the definition, but I decided to debug and
checked for the fixtures existence even without the definition and all
of them had been loaded. So what’s the purpose of the declaration?

Of course they are there - you loaded them. However, consider this test
suite:

class SomeTests …

def test_aardvark
  screw_users_table_up()
  assert{ users_table_is_screwed_up() }
end

def test_zebra
  deny{ users_table_is_screwed_up() }
end

end

The test case names force [the current version of] test/unit to run
those cases
in that order.

The second test will fail because the first one screwed the table up.

The ‘fixtures :users’ line means “please un-screw-up the users table
between
each test case”. Adding it to my hypothetical test suite would “fix” it.

The fixture system enables “Test Isolation”. You could run any test
case, in any
order, or not at all, and each one should not add any noise to the
signal from
any other.


Phlip


#4

On Thu, Mar 26, 2009 at 8:43 AM, Frederick C.
removed_email_address@domain.invalid wrote:

For a while rails apps (by default) have fixtures :all in their
test_helper.rb, which does pretty much what you would imagine.

When I moved an app from 2.2.2 to 2.3.2 a couple days ago, I was
prompted to remove the fixtures :all from my test_helper.rb,
deprecation warning if I recall correctly. And then removing it broke
all my tests. I had to put explicit fixture entries back into in all
my tests to get them working again.


Greg D.
http://destiney.com/


#5

On Mar 26, 12:27 am, yachtman removed_email_address@domain.invalid wrote:

Is it necessary to define fixtures in my test file
(‘fixtures :users’)?

My test are working with the definition, but I decided to debug and
checked for the fixtures existence even without the definition and all
of them had been loaded. So what’s the purpose of the declaration?

For a while rails apps (by default) have fixtures :all in their
test_helper.rb, which does pretty much what you would imagine.

Fred