What is the standard way to put a standard set of asserts into acalled subroutine in test/unit?

Discussion in 'Ruby' started by Xeno Campanoli / Eskimo North and Gmail, Apr 30, 2010.

  1. I want to do something like:

    require 'test/unit'

    class TestMyStuff < Test::Unit::TestCase

    def mysub(x,y)
    assert_not_nil(x,"x nil")
    assert_not_nil(y,"y nil")
    assert(x == y,"messages")
    end

    def test_my_stuff
    mysub(X,Y)
    end

    end
    --
    "It's the preponderance, stupid!" - Professor Stephen Schneider, IPCC member
     
    Xeno Campanoli / Eskimo North and Gmail, Apr 30, 2010
    #1
    1. Advertising

  2. On 4/30/10, Xeno Campanoli / Eskimo North and Gmail
    <> wrote:
    > I want to do something like:
    >
    > require 'test/unit'
    >
    > class TestMyStuff < Test::Unit::TestCase
    >
    > def mysub(x,y)
    > assert_not_nil(x,"x nil")
    > assert_not_nil(y,"y nil")
    > assert(x == y,"messages")
    > end
    >
    > def test_my_stuff
    > mysub(X,Y)
    > end
    >
    > end


    Yes, and? That works perfectly for me. I do it all the time.
     
    Caleb Clausen, Apr 30, 2010
    #2
    1. Advertising

  3. Xeno Campanoli / Eskimo North and Gmail

    Phlip Guest

    On Apr 30, 2:42 pm, Xeno Campanoli / Eskimo North and Gmail
    <> wrote:
    > I want to do something like:
    >
    > require 'test/unit'
    >
    > class TestMyStuff < Test::Unit::TestCase
    >
    >         def mysub(x,y)
    >                 assert_not_nil(x,"x nil")
    >                 assert_not_nil(y,"y nil")
    >                 assert(x == y,"messages")
    >         end


    Call it assert_mysub().

    In general, generic assertions have mundane names, such as
    assert_equal, and application-specific assertions have long names that
    reveal their application-specific intent. Such as assert_x_and_y.

    Next, all tests use the pattern Assemble, Activate, Assert, but your
    test case might be missing its Activate line. The line that actually
    does something important, in your production code! That pattern is,
    generally, why I always call the assembly methods "assemble_", and I
    always call assertions "assert_".

    And, as always, props for writing developer tests. You are now among
    the top 5% of all programmers. (More's the pity!;)

    --
    Phlip
    http://c2.com/cgi/wiki?ZeekLand
     
    Phlip, May 5, 2010
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Timothy Grant

    py.test munging strings in asserts?

    Timothy Grant, Apr 21, 2006, in forum: Python
    Replies:
    1
    Views:
    327
    Johnny deBris
    Apr 21, 2006
  2. VvanN
    Replies:
    5
    Views:
    512
    Phlip
    Apr 28, 2006
  3. Daniel Berger

    Multiple asserts in a single unit test

    Daniel Berger, Apr 15, 2005, in forum: Ruby
    Replies:
    6
    Views:
    164
    Eric Hodel
    Apr 16, 2005
  4. timr
    Replies:
    2
    Views:
    179
  5. king
    Replies:
    5
    Views:
    210
Loading...

Share This Page