--2oox5VnwalALFvA7
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

Daniel Carrera (dcarrera / math.umd.edu) wrote:

> I'm trying to figure out how to ust Test::Unit.  I've read the 
> documentation in:
> http://testunit.talbott.ws/doc/index.html
> 
> But I'm no closer to understanding it than I was before.  At the end of 
> the page, the author says that (s)he'd like to get some feedback.  Whoever 
> the author might be, here is some feedback:
> 
> 1) Include your name and email so that it's easier to send you feedback.
> 2) Could you include an example of how I'd use Test::Unit?

You mean you read the whole page and didn't see the Feedback, Contact
Information or Author headings?

> Here is a simple case.  Say I write a private method to add two numbers:
> 
> class MyClass
>   private
>     def add(a,b)
>         return a+b
>     end
> end
> 
> And I want to - say - assert that the return value is larger than the 
> first input value.  How can I use Test::Unit to make this assertion?

You don't; unit tests test the public interface.  If this method wasn't
private, you could test it something like:

require 'test/unit'

class TC_MyClass < Test::Unit::TestCase
  def test_add
    my_obj = MyClass.new
    assert_equal(5, my_obj(3,2), 'Add should work just like Fixnum#+')
  end
end

> How can I use Test::Unit to assert in-between steps inside my methods?

You don't, that's not what unit testing is about

> Currently I have things like:
> 
> condition or raise "condition was not met"

assert_foo(expected, condition, message)

Read about the assert_* methods on the page above

> How can I replace this sort of thing by test units?

-- 
Eric Hodel - drbrain / segment7.net - http://segment7.net
All messages signed with fingerprint:
FEC2 57F1 D465 EB15 5D6E  7C11 332A 551C 796C 9F04


--2oox5VnwalALFvA7
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (FreeBSD)

iD8DBQE+UWJeMypVHHlsnwQRAqyAAKC/O9uH3Klx65YfTIeB3fjG2c91CQCfeJGq
VpTtGqIw4XnJpsXnjXco8OAeD
-----END PGP SIGNATURE-----

--2oox5VnwalALFvA7--