# Ruby Testing

**URL:** <https://www.ruby-forum.com/t/ruby-testing/122805>\
**Category:** Rails\
**Created:** [December 12, 2007, 11:36am UTC](https://www.ruby-forum.com/t/ruby-testing/122805 "2007-12-12T11:36:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![manjularaj](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/91b2a8/32.png) [@manjularaj](https://www.ruby-forum.com/u/manjularaj)\
**Post date:** [December 12, 2007, 11:36am UTC](https://www.ruby-forum.com/t/ruby-testing/122805/1 "2007-12-12T11:36:45Z")

</div>

Hi,

How do i write unit test without writing the validations? Is it possible  
to write the unit test or functional test before writing the validation  
and controller code?

manjula

---

<div class="post-metadata">

**Author:** ![manjularaj](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/91b2a8/32.png) [@manjularaj](https://www.ruby-forum.com/u/manjularaj)\
**Post date:** [December 12, 2007, 12:18pm UTC](https://www.ruby-forum.com/t/ruby-testing/122805/2 "2007-12-12T12:18:53Z")

</div>

On 12 Dec 2007, at 10:36, Manjula R. wrote:

> Hi,
> 
> How do i write unit test without writing the validations? Is it  
> possible  
> to write the unit test or functional test before writing the  
> validation  
> and controller code?

You can definitely write a test without having written the controller/  
model code. Obviously the test should at that point fail (if not your  
test is broken).  
People sometimes call this test-first development. It does require  
that you think about what your model should be doing before having  
actually written it (which in my book is a good thing).

Fred

---

<div class="post-metadata">

**Author:** ![manjularaj](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/91b2a8/32.png) [@manjularaj](https://www.ruby-forum.com/u/manjularaj)\
**Post date:** [December 13, 2007, 5:52am UTC](https://www.ruby-forum.com/t/ruby-testing/122805/3 "2007-12-13T05:52:40Z")

</div>

Hi,

how do i write the test case for checking the length.

def test\_for\_ssn\_no  
contact = Contact.new  
contact.ssn\_no = ‘-123f4’  
assert !contact.valid?  
assert\_equal ‘-123f456e7t’, contact.ssn\_no, “Pass”  
end

This is my test case. I want to check the length of ssn\_no should be not  
more than 10 digits. How do i write. And the above code is the right  
way to write the test case? Please help me out to write a good test  
cases.
