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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Unit Test a database update code?

Unit Test a database update code?

Scheduled Pinned Locked Moved C#
csharpquestiondatabasevisual-studiotesting
5 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.
  • S Offline
    S Offline
    Shubhabrata Mohanty
    wrote on last edited by
    #1

    Hi - I have a piece of C# code that write message log to Database. Now I would like to create unit test scripts using Visual Studio Unit Test framework. I need to create Unit Test code to verify if the data is written properly to the database or not. How do I write code or what mechanism I should use to verify this. Thanks, Shub

    L A L R 4 Replies Last reply
    0
    • S Shubhabrata Mohanty

      Hi - I have a piece of C# code that write message log to Database. Now I would like to create unit test scripts using Visual Studio Unit Test framework. I need to create Unit Test code to verify if the data is written properly to the database or not. How do I write code or what mechanism I should use to verify this. Thanks, Shub

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      I think, use "INSERT..." command. And read it back using "SELECT...". If input==output, then OK, otherwise ERROR.

      1 Reply Last reply
      0
      • S Shubhabrata Mohanty

        Hi - I have a piece of C# code that write message log to Database. Now I would like to create unit test scripts using Visual Studio Unit Test framework. I need to create Unit Test code to verify if the data is written properly to the database or not. How do I write code or what mechanism I should use to verify this. Thanks, Shub

        A Offline
        A Offline
        Abhinav S
        wrote on last edited by
        #3

        See here[^].

        The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it. My latest tip/trick Visit the Hindi forum here.

        1 Reply Last reply
        0
        • S Shubhabrata Mohanty

          Hi - I have a piece of C# code that write message log to Database. Now I would like to create unit test scripts using Visual Studio Unit Test framework. I need to create Unit Test code to verify if the data is written properly to the database or not. How do I write code or what mechanism I should use to verify this. Thanks, Shub

          L Offline
          L Offline
          LLambert
          wrote on last edited by
          #4

          Well in my opinion doing a unit test does not involve actually seeing if the data got written properly to the database. That is an integration test in my opinion. Unit tests should just test that module and nothing else. I would make a mock database adaptor and have the test make sure all the proper commands where made to the adaptor from your code. To me this is a truer unit test.

          Leon Lambert

          1 Reply Last reply
          0
          • S Shubhabrata Mohanty

            Hi - I have a piece of C# code that write message log to Database. Now I would like to create unit test scripts using Visual Studio Unit Test framework. I need to create Unit Test code to verify if the data is written properly to the database or not. How do I write code or what mechanism I should use to verify this. Thanks, Shub

            R Offline
            R Offline
            Richard A Dalton
            wrote on last edited by
            #5

            You have two choices. First choice is actually write the data to the Database, ideally within a transation so that it can be rolled back. You need to be able to run your Unit Tests repeatedly without leaving a mess behind. Second Choice is to Mock the Database. If you haven't designed your app from the start with this in mind then it can be tricky to retrofit. If you need more info on Mocking just ask. -Rd

            Hit any user to continue.

            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