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. General Programming
  3. C#
  4. writing good unit tests

writing good unit tests

Scheduled Pinned Locked Moved C#
questiontutorial
4 Posts 3 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.
  • S Offline
    S Offline
    steven shingler
    wrote on last edited by
    #1

    Hi all, I'm just getting into writing unit tests - can see the benefits of them for sure. I get the impression that there is quite a bit of skill and know-how in writing decent tests that are worth their salt. The tests are only as good as the coder writing them, eh? ;) It would be great to see some examples beyond the example of the bank account that is given with nunit. I wondered if anyone here knows of any good examples of some unit tests on a more involved real world application? Or if anyone has any thought or advice on this matter it would be great to hear too. Sorry it's a bit of a vague question - :) But very much looking forward to your replies. Best wishes Steven

    C M 2 Replies Last reply
    0
    • S steven shingler

      Hi all, I'm just getting into writing unit tests - can see the benefits of them for sure. I get the impression that there is quite a bit of skill and know-how in writing decent tests that are worth their salt. The tests are only as good as the coder writing them, eh? ;) It would be great to see some examples beyond the example of the bank account that is given with nunit. I wondered if anyone here knows of any good examples of some unit tests on a more involved real world application? Or if anyone has any thought or advice on this matter it would be great to hear too. Sorry it's a bit of a vague question - :) But very much looking forward to your replies. Best wishes Steven

      C Offline
      C Offline
      Colin Angus Mackay
      wrote on last edited by
      #2

      Not really got any examples I could share but some ideas to help you out: * Test with good input * Test with bad input * Test with input at the edge of valid ranges. e.g. If your method can accept an integer in the range 1 to 100 test that 0 and 101 fail properly (throwing the correct exception, or returning the appropriate success indicator), and test that 1 and 100 work. * Test different combinations of data. e.g. if it doesn't matter which order two parameters are given, then check that by testing with these parameters in a different order. * Look at the possible code paths inside your method and try and construct tests that will take the code through each of the possible paths. Probably other people will reply also with other ideas, but these are some that immediately spring to mind.


      "You can have everything in life you want if you will just help enough other people get what they want." --Zig Ziglar The Second EuroCPian Event will be in Brussels on the 4th of September Can't manage to P/Invoke that Win32 API in .NET? Why not do interop the wiki way! My Blog

      S 1 Reply Last reply
      0
      • C Colin Angus Mackay

        Not really got any examples I could share but some ideas to help you out: * Test with good input * Test with bad input * Test with input at the edge of valid ranges. e.g. If your method can accept an integer in the range 1 to 100 test that 0 and 101 fail properly (throwing the correct exception, or returning the appropriate success indicator), and test that 1 and 100 work. * Test different combinations of data. e.g. if it doesn't matter which order two parameters are given, then check that by testing with these parameters in a different order. * Look at the possible code paths inside your method and try and construct tests that will take the code through each of the possible paths. Probably other people will reply also with other ideas, but these are some that immediately spring to mind.


        "You can have everything in life you want if you will just help enough other people get what they want." --Zig Ziglar The Second EuroCPian Event will be in Brussels on the 4th of September Can't manage to P/Invoke that Win32 API in .NET? Why not do interop the wiki way! My Blog

        S Offline
        S Offline
        steven shingler
        wrote on last edited by
        #3

        Thanks Colin, That's great.:) Makes sense and I'll give it a go. Cheers Steven

        1 Reply Last reply
        0
        • S steven shingler

          Hi all, I'm just getting into writing unit tests - can see the benefits of them for sure. I get the impression that there is quite a bit of skill and know-how in writing decent tests that are worth their salt. The tests are only as good as the coder writing them, eh? ;) It would be great to see some examples beyond the example of the bank account that is given with nunit. I wondered if anyone here knows of any good examples of some unit tests on a more involved real world application? Or if anyone has any thought or advice on this matter it would be great to hear too. Sorry it's a bit of a vague question - :) But very much looking forward to your replies. Best wishes Steven

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

          steven shingler wrote: It would be great to see some examples beyond the example of the bank account that is given with nunit. Ever heard of google? I've written several articles on unit testing, and that's just me! :rolleyes: http://www.google.com/search?hl=en&ie=UTF-8&q=unit+test+site%3Acodeproject.com[^] Marc Microsoft MVP, Visual C# MyXaml MyXaml Blog

          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