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. Product Lifecycle
  3. Collaboration / Beta Testing
  4. unit_testing : granularity of tests

unit_testing : granularity of tests

Scheduled Pinned Locked Moved Collaboration / Beta Testing
questiontestingbeta-testinghelp
3 Posts 2 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.
  • J Offline
    J Offline
    Jerome Conus
    wrote on last edited by
    #1

    Hi ! I'm new to unit testing and I need some clarification. I want to test a class. When I create an instance of this class with the default constructor, I need to check 3 values and make sure they are initialised to the correct default values (for instance : a name property). Do I have to code three tests (one for each value to test) or can I create one test for the default construction of the instance and check, in the same test, the 3 values ? Hope my question is understandable ! Thanks for your help ! Jerome

    R 1 Reply Last reply
    0
    • J Jerome Conus

      Hi ! I'm new to unit testing and I need some clarification. I want to test a class. When I create an instance of this class with the default constructor, I need to check 3 values and make sure they are initialised to the correct default values (for instance : a name property). Do I have to code three tests (one for each value to test) or can I create one test for the default construction of the instance and check, in the same test, the 3 values ? Hope my question is understandable ! Thanks for your help ! Jerome

      R Offline
      R Offline
      Roger Wright
      wrote on last edited by
      #2

      There is no good reason to test each value separately. Your "unit" consists of the class itself, I assume, and your unit test should verify the class as a whole. If there is something unique about the way values are accessed, then the test should take that into account. But if they're accessible as a group, go ahead. Your test also should include verification of the methods within the class, and should be structured so that all private methods are utilized during the test. If the class has any dependencies on other classes, make sure that you exercise them thoroughly. Ideally, you should also try testing error conditions; try things you never intended the class to do and check how gracefully it fails. Use out of range values, incorrect variable types, and edge-of-limit values if there are any limit tests required. As a general guide, try to imagine what the dumbest consumer of your class might attempt to do to it, then duplicate that in your test. We used to call that "dummy-proofing" before there was such a thing as formal unit testing, and it worked remarkably well.:-D "...putting all your eggs in one basket along with your bowling ball and gym clothes only gets you scrambled eggs and an extra laundry day... " - Jeffry J. Brickley

      J 1 Reply Last reply
      0
      • R Roger Wright

        There is no good reason to test each value separately. Your "unit" consists of the class itself, I assume, and your unit test should verify the class as a whole. If there is something unique about the way values are accessed, then the test should take that into account. But if they're accessible as a group, go ahead. Your test also should include verification of the methods within the class, and should be structured so that all private methods are utilized during the test. If the class has any dependencies on other classes, make sure that you exercise them thoroughly. Ideally, you should also try testing error conditions; try things you never intended the class to do and check how gracefully it fails. Use out of range values, incorrect variable types, and edge-of-limit values if there are any limit tests required. As a general guide, try to imagine what the dumbest consumer of your class might attempt to do to it, then duplicate that in your test. We used to call that "dummy-proofing" before there was such a thing as formal unit testing, and it worked remarkably well.:-D "...putting all your eggs in one basket along with your bowling ball and gym clothes only gets you scrambled eggs and an extra laundry day... " - Jeffry J. Brickley

        J Offline
        J Offline
        Jerome Conus
        wrote on last edited by
        #3

        Thanks Roger for your answer. It clarifies a lot what I have to do ! Jerome

        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