Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. More unit testing questions....

More unit testing questions....

Scheduled Pinned Locked Moved The Lounge
testingcollaborationbeta-testingquestion
6 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    BrockVnm
    wrote on last edited by
    #1

    Hey everyone, I have a few small questions on unit testing. I am kind of doing this backwards because my team is starting to make everyone do unit tests on there code and they want me to start with code that I have already written. So I am looking through my code and not sure what functions to unit test. I know you dont usually unit test GUI, or set and get functions. I have functions that load tables, generate reports and emails. Should I also unit test these functions? Thanks for all of your advice! :-D


    There are 10 kinds of people in this world. Those who understand binary and those who don't. We shouldn't assume something's debugged just because everyone in the whole world has access to the source code.

    N M P 3 Replies Last reply
    0
    • B BrockVnm

      Hey everyone, I have a few small questions on unit testing. I am kind of doing this backwards because my team is starting to make everyone do unit tests on there code and they want me to start with code that I have already written. So I am looking through my code and not sure what functions to unit test. I know you dont usually unit test GUI, or set and get functions. I have functions that load tables, generate reports and emails. Should I also unit test these functions? Thanks for all of your advice! :-D


      There are 10 kinds of people in this world. Those who understand binary and those who don't. We shouldn't assume something's debugged just because everyone in the whole world has access to the source code.

      N Offline
      N Offline
      Navin
      wrote on last edited by
      #2

      Well, I try to unit test anything that is not trivial and has a well-defined result such that a test can be automated. For functions that load tables, you might be able to unit-test it by loading a table with some known data, and then querying to ensure that the data you expected got loaded into the table. Generating e-mails might be tougher to automate, but there are probably ways of doing that. Generating a report might be unit testable - but if the report is really just a human-readable presentation of data, that probably can't be unit tested very easily. Other sources of unit tests are past bugs - sometimes if I get a bug report, I try to create a unit test that breaks, exposing the bug. Then I have a good idea that the bug is fixed when the unit test passes. Unit tests are a great aid to testing and development, but of course there are not for everything. Things that can't be unit tested very well (e.g., your GUI) still need to be tested, just by other means. The generation of random numbers is too important to be left to chance.

      P 1 Reply Last reply
      0
      • N Navin

        Well, I try to unit test anything that is not trivial and has a well-defined result such that a test can be automated. For functions that load tables, you might be able to unit-test it by loading a table with some known data, and then querying to ensure that the data you expected got loaded into the table. Generating e-mails might be tougher to automate, but there are probably ways of doing that. Generating a report might be unit testable - but if the report is really just a human-readable presentation of data, that probably can't be unit tested very easily. Other sources of unit tests are past bugs - sometimes if I get a bug report, I try to create a unit test that breaks, exposing the bug. Then I have a good idea that the bug is fixed when the unit test passes. Unit tests are a great aid to testing and development, but of course there are not for everything. Things that can't be unit tested very well (e.g., your GUI) still need to be tested, just by other means. The generation of random numbers is too important to be left to chance.

        P Offline
        P Offline
        ProffK
        wrote on last edited by
        #3

        I would test for more than just teh expected data on a table load. What about incorrect table names, closed connections, timeouts etc? His hands felt the grasp of strong white hairs, and he knew he would not survive this fungus.

        1 Reply Last reply
        0
        • B BrockVnm

          Hey everyone, I have a few small questions on unit testing. I am kind of doing this backwards because my team is starting to make everyone do unit tests on there code and they want me to start with code that I have already written. So I am looking through my code and not sure what functions to unit test. I know you dont usually unit test GUI, or set and get functions. I have functions that load tables, generate reports and emails. Should I also unit test these functions? Thanks for all of your advice! :-D


          There are 10 kinds of people in this world. Those who understand binary and those who don't. We shouldn't assume something's debugged just because everyone in the whole world has access to the source code.

          M Offline
          M Offline
          Marc Clifton
          wrote on last edited by
          #4

          Maybe my article on writing your First Unit Test[^] will help. :) Marc MyXaml Advanced Unit Testing YAPO

          B 1 Reply Last reply
          0
          • M Marc Clifton

            Maybe my article on writing your First Unit Test[^] will help. :) Marc MyXaml Advanced Unit Testing YAPO

            B Offline
            B Offline
            BrockVnm
            wrote on last edited by
            #5

            That is what I am looking for. I am going to read it now. I knew you would have something for me Marc....:laugh:


            There are 10 kinds of people in this world. Those who understand binary and those who don't. We shouldn't assume something's debugged just because everyone in the whole world has access to the source code.

            1 Reply Last reply
            0
            • B BrockVnm

              Hey everyone, I have a few small questions on unit testing. I am kind of doing this backwards because my team is starting to make everyone do unit tests on there code and they want me to start with code that I have already written. So I am looking through my code and not sure what functions to unit test. I know you dont usually unit test GUI, or set and get functions. I have functions that load tables, generate reports and emails. Should I also unit test these functions? Thanks for all of your advice! :-D


              There are 10 kinds of people in this world. Those who understand binary and those who don't. We shouldn't assume something's debugged just because everyone in the whole world has access to the source code.

              P Offline
              P Offline
              Paul Ingles
              wrote on last edited by
              #6

              One thing I'd also suggest is taking a look at using Mock objects, they provide a nice way of letting you test interaction between objects that you may or may not be able to test 'reliably'. For instance, say part of your code needs to send emails out, but there's no guarantee that your email server will be alive/accessible to all developers when they're running the unit tests, or to the build/integration server. So, you build your EmailSender type around an interface that you can then call Send upon in your code, with mocks you can dynamically create objects that implement the interface, you can then tell your own code to use the interface on the mock to send the email, and you then test that the mock received the intended call, with the expected parameters etc. It also makes your unit tests nice and quick :) There are a few mock frameworks around for .NET (I don't know what language/libraries you're using), but I'm sure if you were interested specialists in other areas would be able to suggest something. For .NET, check out: http://www.nmock.org/[^] http://msdn.microsoft.com/msdnmag/issues/04/10/NMock/default.aspx[^] and for a more general treatment: http://www.martinfowler.com/articles/mocksArentStubs.html[^] Forgot to mention that although mocks are very useful in the example I mentioned, they also serve a nice way of testing interaction between even non-expensive/trivial types. -- Paul MS Messenger: paul -at- oobaloo-co-uk

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups