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. Are tests ugly?

Are tests ugly?

Scheduled Pinned Locked Moved C#
databasetutorialquestion
2 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.
  • U Offline
    U Offline
    User 4483848
    wrote on last edited by
    #1

    I have written quite a few automated tests now with things like NUnit, and I find that they generally don't look very elegant. I find that code reuse is usually very difficult and code all ends up looking very similar. Books generally only show simple cases and in the real world with databases etc. things aren't quite so simple. A good example of what I mean is database stuff. Every table works in pretty much the same way, but they all have different fields and types so you can't reuse much code. I find that most of my code looks like this: SetupConnectionEtc(); SetupDataForTest(); DoSomething(); ReadTheDataAndCheckEverything(); Although the first line probably isn't unique, all of the others usually are. So if your application uses 20 database tables then you will probably end up with 20 files containing a ReadTheDataAndCheckEverything() function, as well as some of the other ones. What do people think? Am I doing something wrong or is there an easier way?

    R 1 Reply Last reply
    0
    • U User 4483848

      I have written quite a few automated tests now with things like NUnit, and I find that they generally don't look very elegant. I find that code reuse is usually very difficult and code all ends up looking very similar. Books generally only show simple cases and in the real world with databases etc. things aren't quite so simple. A good example of what I mean is database stuff. Every table works in pretty much the same way, but they all have different fields and types so you can't reuse much code. I find that most of my code looks like this: SetupConnectionEtc(); SetupDataForTest(); DoSomething(); ReadTheDataAndCheckEverything(); Although the first line probably isn't unique, all of the others usually are. So if your application uses 20 database tables then you will probably end up with 20 files containing a ReadTheDataAndCheckEverything() function, as well as some of the other ones. What do people think? Am I doing something wrong or is there an easier way?

      R Offline
      R Offline
      Ravi Bhavnani
      wrote on last edited by
      #2

      I find testing (and writing tests) invaluable.  In fact, it's the only reason I sleep soundly at night (no, really).  I'm working on some low-level frameworky stuff (that has to work and has to work fast) and end up writing slightly higher level tests than the ones mentioned in your post. I find them to be more useful (i.e. akin to how my APIs are used) than traditional unit testing. To answer your question, I probably wouldn't write tests that check table reads and writes - instead, I'd write tests for the APIs that end up calling them.  I hope this makes sense. /ravi

      My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

      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