# Why are my unit tests passing?

**URL:** <https://www.ruby-forum.com/t/why-are-my-unit-tests-passing/122125>\
**Category:** Rails\
**Created:** [December 4, 2007, 8:17pm UTC](https://www.ruby-forum.com/t/why-are-my-unit-tests-passing/122125 "2007-12-04T20:17:50Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ian](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/bb73d2/32.png) [@ian](https://www.ruby-forum.com/u/ian)\
**Post date:** [December 4, 2007, 8:17pm UTC](https://www.ruby-forum.com/t/why-are-my-unit-tests-passing/122125/1 "2007-12-04T20:17:50Z")

</div>

Most people want to know why their tests are failing. I want to know  
why they are passing. They really shouldn’t be.

The test environment database defined in database.yml does not exist.  
I have not altered the auto-generated tests at all. When I run the  
following command from the site root:

> ruby test/unit/gender\_test.rb

I expect that this should fail. However, I get

“1 tests, 1 assertions, 0 failures, 0 errors”

I’m working my way through the Prag Prog Agile Rails book. In the  
testing section (page 186), the book says that these tests should fail  
until I create the testing database. Is the book wrong, or do I have  
magic unit tests?

RoR Version: 1.2.3  
Ruby Version: 1.8.6  
DB: Mysql

Thanks for the help.

Ian

---

<div class="post-metadata">

**Author:** ![ian](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/bb73d2/32.png) [@ian](https://www.ruby-forum.com/u/ian)\
**Post date:** [December 4, 2007, 8:33pm UTC](https://www.ruby-forum.com/t/why-are-my-unit-tests-passing/122125/2 "2007-12-04T20:33:22Z")

</div>

Ian wrote:

> Most people want to know why their tests are failing. I want to know  
> why they are passing. They really shouldn’t be.
> 
> The test environment database defined in database.yml does not exist.  
> I have not altered the auto-generated tests at all. When I run the  
> following command from the site root:
> 
> > ruby test/unit/gender\_test.rb
> 
> I expect that this should fail. However, I get
> 
> “1 tests, 1 assertions, 0 failures, 0 errors”
> 
> I’m working my way through the Prag Prog Agile Rails book. In the  
> testing section (page 186), the book says that these tests should fail  
> until I create the testing database. Is the book wrong, or do I have  
> magic unit tests?
> 
> RoR Version: 1.2.3  
> Ruby Version: 1.8.6  
> DB: Mysql
> 
> Thanks for the help.
> 
> Ian

Ian,

By default the test case that is provided by the generator for each  
model is assert\_truth() which returns true so initially “all” test cases  
pass.

---

<div class="post-metadata">

**Author:** ![ian](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/bb73d2/32.png) [@ian](https://www.ruby-forum.com/u/ian)\
**Post date:** [December 4, 2007, 9:17pm UTC](https://www.ruby-forum.com/t/why-are-my-unit-tests-passing/122125/3 "2007-12-04T21:17:54Z")

</div>

Thank you for your reply.

I noticed the simplicity of the default test & have some familiarity  
with both unit testing and Test::Unit. But the example I’m reading  
says that even this very simple test should fail if the database  
doesn’t exist. That’s where my confusion comes from.

On Dec 4, 1:33 pm, Ilan B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![ian](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/bb73d2/32.png) [@ian](https://www.ruby-forum.com/u/ian)\
**Post date:** [December 5, 2007, 9:06pm UTC](https://www.ruby-forum.com/t/why-are-my-unit-tests-passing/122125/4 "2007-12-05T21:06:02Z")

</div>

Ian,

> I noticed the simplicity of the default test & have some familiarity  
> with both unit testing and Test::Unit. But the example I’m reading  
> says that even this very simple test should fail if the database  
> doesn’t exist. That’s where my confusion comes from.

Do you have any fixtures declared in your tests? If not, then Rails  
might not be bothering to connect to the database at all.

## Jim

Jim M., removed\_email\_address@domain.invalid, removed\_email\_address@domain.invalid  
[http://www.io.com/~jimm/](http://www.io.com/~jimm/)
