Nunit question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Alvin Bruney

    #1

    Nunit question


    I've a question on unit testing with NUnit. I'm sure I'm missing just a
    little thing here. Why doesn't NUnit allow me to test a routine with
    parameter in it like what i want to do is test

    [TestFixture]
    private string testme(string test)
    and put my test code in there. So why the emphasis on having me write a
    specific routine with a void return type and an empty parameter? Is it
    because its forcing me to write a routine to call testme to make sure it
    works? Not really sure here. Please advise.

    Nial, Skeet, and other Unit advocates
    thanks for pushing this. I'm using it in a new project now. I've gotten
    really fed up of touching code, introducing bugs and having someone yell at
    me rather loudly for insufficient regression testing.

    --
    Regards,
    Alvin Bruney
    (dont really know how to sign my name here because of the imposter)
    Got Tidbits? Get it here
    NetworkIP helps MNOs and MVNOs launch bundled and add-on international calling with direct US carrier connections, low risk and 25+ years of telecom expertise.



  • Jon Skeet [C# MVP]

    #2
    Re: Nunit question

    Alvin Bruney <vapordan@hotsp ammailme.com> wrote:[color=blue]
    > I've a question on unit testing with NUnit. I'm sure I'm missing just a
    > little thing here. Why doesn't NUnit allow me to test a routine with
    > parameter in it like what i want to do is test
    >
    > [TestFixture]
    > private string testme(string test)
    > and put my test code in there. So why the emphasis on having me write a
    > specific routine with a void return type and an empty parameter? Is it
    > because its forcing me to write a routine to call testme to make sure it
    > works? Not really sure here. Please advise.[/color]

    The point is that the methods will be called automatically, and there
    won't be anything to work out what parameter to call it with.

    Note that the TestFixtures aren't really the methods you're testing -
    they're the methods which *call* the methods you're testing. So for
    instance, you might have a method which (say) counts the number of
    characters in a string. You would then write a test fixture (without
    any parameters) which called that method several times with different
    parameters, checking that the right thing happens if you pass in null,
    etc.
    [color=blue]
    > Nial, Skeet, and other Unit advocates
    > thanks for pushing this. I'm using it in a new project now. I've gotten
    > really fed up of touching code, introducing bugs and having someone yell at
    > me rather loudly for insufficient regression testing.[/color]

    Good luck with it! (Are you hoping to get to the stage where you get
    everyone else in your team to use unit testing too?)

    --
    Jon Skeet - <skeet@pobox.co m>
    Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

    If replying to the group, please do not mail me too

    Comment

    • Alvin Bruney

      #3
      Re: Nunit question

      > Good luck with it! (Are you hoping to get to the stage where you get[color=blue]
      > everyone else in your team to use unit testing too?)[/color]

      Yes, i'm planning a small demo for the end of next week on this to intoduce
      it to the group which is why I'm asking these silly questions.

      --
      Regards,
      Alvin Bruney
      Got Tidbits? Get it here
      NetworkIP helps MNOs and MVNOs launch bundled and add-on international calling with direct US carrier connections, low risk and 25+ years of telecom expertise.

      "Jon Skeet [C# MVP]" <skeet@pobox.co m> wrote in message
      news:MPG.1a326e bb747c005c989b6 f@msnews.micros oft.com...[color=blue]
      > Alvin Bruney <vapordan@hotsp ammailme.com> wrote:[color=green]
      > > I've a question on unit testing with NUnit. I'm sure I'm missing just a
      > > little thing here. Why doesn't NUnit allow me to test a routine with
      > > parameter in it like what i want to do is test
      > >
      > > [TestFixture]
      > > private string testme(string test)
      > > and put my test code in there. So why the emphasis on having me write a
      > > specific routine with a void return type and an empty parameter? Is it
      > > because its forcing me to write a routine to call testme to make sure it
      > > works? Not really sure here. Please advise.[/color]
      >
      > The point is that the methods will be called automatically, and there
      > won't be anything to work out what parameter to call it with.
      >
      > Note that the TestFixtures aren't really the methods you're testing -
      > they're the methods which *call* the methods you're testing. So for
      > instance, you might have a method which (say) counts the number of
      > characters in a string. You would then write a test fixture (without
      > any parameters) which called that method several times with different
      > parameters, checking that the right thing happens if you pass in null,
      > etc.
      >[color=green]
      > > Nial, Skeet, and other Unit advocates
      > > thanks for pushing this. I'm using it in a new project now. I've gotten
      > > really fed up of touching code, introducing bugs and having someone yell[/color][/color]
      at[color=blue][color=green]
      > > me rather loudly for insufficient regression testing.[/color]
      >
      > Good luck with it! (Are you hoping to get to the stage where you get
      > everyone else in your team to use unit testing too?)
      >
      > --
      > Jon Skeet - <skeet@pobox.co m>
      > http://www.pobox.com/~skeet
      > If replying to the group, please do not mail me too[/color]


      Comment

      • Alvin Bruney

        #4
        Re: Nunit question

        Also what happens at release time, do I need to remove all these tests or
        can they be turned off to evaluate to whitespace? I'm concerned about
        increased memory footprints with these testing units being added in and how
        they affect performance.

        --
        Regards,
        Alvin Bruney
        Got Tidbits? Get it here
        NetworkIP helps MNOs and MVNOs launch bundled and add-on international calling with direct US carrier connections, low risk and 25+ years of telecom expertise.

        "Alvin Bruney" <vapordan@hotsp ammailme.com> wrote in message
        news:eLBCgDptDH A.1888@TK2MSFTN GP10.phx.gbl...[color=blue][color=green]
        > > Good luck with it! (Are you hoping to get to the stage where you get
        > > everyone else in your team to use unit testing too?)[/color]
        >
        > Yes, i'm planning a small demo for the end of next week on this to[/color]
        intoduce[color=blue]
        > it to the group which is why I'm asking these silly questions.
        >
        > --
        > Regards,
        > Alvin Bruney
        > Got Tidbits? Get it here
        > www.networkip.net/tidbits
        > "Jon Skeet [C# MVP]" <skeet@pobox.co m> wrote in message
        > news:MPG.1a326e bb747c005c989b6 f@msnews.micros oft.com...[color=green]
        > > Alvin Bruney <vapordan@hotsp ammailme.com> wrote:[color=darkred]
        > > > I've a question on unit testing with NUnit. I'm sure I'm missing just[/color][/color][/color]
        a[color=blue][color=green][color=darkred]
        > > > little thing here. Why doesn't NUnit allow me to test a routine with
        > > > parameter in it like what i want to do is test
        > > >
        > > > [TestFixture]
        > > > private string testme(string test)
        > > > and put my test code in there. So why the emphasis on having me write[/color][/color][/color]
        a[color=blue][color=green][color=darkred]
        > > > specific routine with a void return type and an empty parameter? Is it
        > > > because its forcing me to write a routine to call testme to make sure[/color][/color][/color]
        it[color=blue][color=green][color=darkred]
        > > > works? Not really sure here. Please advise.[/color]
        > >
        > > The point is that the methods will be called automatically, and there
        > > won't be anything to work out what parameter to call it with.
        > >
        > > Note that the TestFixtures aren't really the methods you're testing -
        > > they're the methods which *call* the methods you're testing. So for
        > > instance, you might have a method which (say) counts the number of
        > > characters in a string. You would then write a test fixture (without
        > > any parameters) which called that method several times with different
        > > parameters, checking that the right thing happens if you pass in null,
        > > etc.
        > >[color=darkred]
        > > > Nial, Skeet, and other Unit advocates
        > > > thanks for pushing this. I'm using it in a new project now. I've[/color][/color][/color]
        gotten[color=blue][color=green][color=darkred]
        > > > really fed up of touching code, introducing bugs and having someone[/color][/color][/color]
        yell[color=blue]
        > at[color=green][color=darkred]
        > > > me rather loudly for insufficient regression testing.[/color]
        > >
        > > Good luck with it! (Are you hoping to get to the stage where you get
        > > everyone else in your team to use unit testing too?)
        > >
        > > --
        > > Jon Skeet - <skeet@pobox.co m>
        > > http://www.pobox.com/~skeet
        > > If replying to the group, please do not mail me too[/color]
        >
        >[/color]


        Comment

        • Jon Skeet [C# MVP]

          #5
          Re: Nunit question

          Alvin Bruney <vapordan@hotsp ammailme.com> wrote:[color=blue]
          > Also what happens at release time, do I need to remove all these tests or
          > can they be turned off to evaluate to whitespace? I'm concerned about
          > increased memory footprints with these testing units being added in and how
          > they affect performance.[/color]

          The increased memory footprints are likely to be absolutely tiny - but
          one thing you could do is put the tests in a different assembly. Don't
          forget that unless you actually call the testing method, it won't get
          JITted, so it'll only be present in IL form. It may not even end up
          getting loaded into memory.

          --
          Jon Skeet - <skeet@pobox.co m>
          Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

          If replying to the group, please do not mail me too

          Comment

          • Daniel O'Connell

            #6
            Re: Nunit question


            "Jon Skeet [C# MVP]" <skeet@pobox.co m> wrote in message
            news:MPG.1a3306 5a53eb435a989b7 2@msnews.micros oft.com...[color=blue]
            > Alvin Bruney <vapordan@hotsp ammailme.com> wrote:[color=green]
            > > Also what happens at release time, do I need to remove all these tests[/color][/color]
            or[color=blue][color=green]
            > > can they be turned off to evaluate to whitespace? I'm concerned about
            > > increased memory footprints with these testing units being added in and[/color][/color]
            how[color=blue][color=green]
            > > they affect performance.[/color]
            >
            > The increased memory footprints are likely to be absolutely tiny - but
            > one thing you could do is put the tests in a different assembly. Don't
            > forget that unless you actually call the testing method, it won't get
            > JITted, so it'll only be present in IL form. It may not even end up
            > getting loaded into memory.
            >[/color]
            Shouldn't you just be able to wrap them in preprocessor blocks?
            #if DEBUG
            //Tests

            #endif

            Its not the prettiest method, but it should allow you to dump them totally
            in release builds. While I wouldn't worry about space so much, I'm hesistent
            at times to leave tests sitting in an assembly that can be called by
            reflection, considering my testing doesn't take into account execution of
            the tests. Its probably unimportant, but if you can't split them off to a
            seperate assembly, the conditional blocks should work.
            [color=blue]
            > --
            > Jon Skeet - <skeet@pobox.co m>
            > http://www.pobox.com/~skeet
            > If replying to the group, please do not mail me too[/color]


            Comment

            • Jon Skeet [C# MVP]

              #7
              Re: Nunit question

              Daniel O'Connell <onyxkirx@--NOSPAM--comcast.net> wrote:[color=blue]
              > Shouldn't you just be able to wrap them in preprocessor blocks?
              > #if DEBUG
              > //Tests
              >
              > #endif
              >
              > Its not the prettiest method, but it should allow you to dump them totally
              > in release builds. While I wouldn't worry about space so much, I'm hesistent
              > at times to leave tests sitting in an assembly that can be called by
              > reflection, considering my testing doesn't take into account execution of
              > the tests. Its probably unimportant, but if you can't split them off to a
              > seperate assembly, the conditional blocks should work.[/color]

              Yes, you certainly could leave them out of release builds. On the other
              hand, to not unit test release builds as well as debug builds might be
              dangerous too...

              --
              Jon Skeet - <skeet@pobox.co m>
              Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

              If replying to the group, please do not mail me too

              Comment

              • Daniel O'Connell

                #8
                Re: Nunit question


                "Jon Skeet [C# MVP]" <skeet@pobox.co m> wrote in message
                news:MPG.1a341b 7ae0bfa075989b7 4@msnews.micros oft.com...[color=blue]
                > Daniel O'Connell <onyxkirx@--NOSPAM--comcast.net> wrote:[color=green]
                > > Shouldn't you just be able to wrap them in preprocessor blocks?
                > > #if DEBUG
                > > //Tests
                > >
                > > #endif
                > >
                > > Its not the prettiest method, but it should allow you to dump them[/color][/color]
                totally[color=blue][color=green]
                > > in release builds. While I wouldn't worry about space so much, I'm[/color][/color]
                hesistent[color=blue][color=green]
                > > at times to leave tests sitting in an assembly that can be called by
                > > reflection, considering my testing doesn't take into account execution[/color][/color]
                of[color=blue][color=green]
                > > the tests. Its probably unimportant, but if you can't split them off to[/color][/color]
                a[color=blue][color=green]
                > > seperate assembly, the conditional blocks should work.[/color]
                >
                > Yes, you certainly could leave them out of release builds. On the other
                > hand, to not unit test release builds as well as debug builds might be
                > dangerous too...[/color]

                Well, ideally, I suppose you wouldn't use #if DEBUG, but #if TESTEDBUILD or
                something, so that a release build can exist with the tests(as well as
                removing the tests during debug to make sure no method calls one for some
                silly reason or another).
                I strongly prefer to put tests in a seperate assembly, anyway.
                [color=blue]
                >
                > --
                > Jon Skeet - <skeet@pobox.co m>
                > http://www.pobox.com/~skeet
                > If replying to the group, please do not mail me too[/color]


                Comment

                Working...