I've a credit card applicatoin that's database intensive. The majority of the programs techniques are upgrading data inside a database. Some calls are wrappers to saved methods while some perform database updates in-code using third party APIs.

What must i be testing during my unit tests? Must I...

  1. Test that every method completes without tossing the best -or-
  2. Validate the information within the database after each test to make certain the condition of information is really as expected

My primary thought is #2 but my problem is which i could be writing a lot of framework code to accompany my unit tests. I just read that you simply should not write a lot of framework code for unit testing.

Ideas?

EDIT: What i'm saying by framework is writing a lot of other code that works as a library towards the unit testing code...not a 3rd party framework.

I actually do number two, i.e., test the update by upgrading an archive, after which reading through it out and verifying the values overlap with those you devote. Do both update and also the read inside a transaction, after which roll it back, to prevent permanent impact on the database. I do not think about this as testing Framework code, anymore than I think about it as being testing OS code or networking code... The framework (should you mean a non-application specific Database access layer component) ought to be examined and validated individually.

You have to test the particular effect from the code around the data, and it is compliance using the validation rules etc., not only that no exceptions are elevated - that might be a little like just checking a process compiles!

It is difficult testing database code that works card inserts, updates or removes (DML), since the test changes the atmosphere it runs in, i.e. the database. Running exactly the same procedure several occasions consecutively could (and most likely should) have spun sentences every time. This is dissimilar to unit testing "pure code", which you'll run 1000's of occasions and try to obtain the same result - i.e. "pure code" is deterministic, database code that works DML isn't.

Because of this, you need to do frequently have to develop a "framework"to aid database unit tests - i.e. scripts to setup some test data within the right condition, and also to cleanup following the test continues to be run.

There is a third option, which would be to make use of a mock database-access object that understands how to react to an update as though it absolutely was attached to an active database, however it does not really execute the query against a database.

This method may be used to supplement testing against an active database. This really is different then testing against an active database, and should not substitute for your type of testing. But you can use it a minimum of to check the invocation from the database update because of your class ended with proper inputs. Additionally, it typically runs much faster than running tests against a genuine database.

If you're not conntacting the database by hand and taking advantage of a framework rather (jvm, .internet framework, ...), you are able to securely think that the framework creates to database properly. That which you must test is if you work with the framework properly.

Just mock the database techniques and objects. Test if you're giving them a call and locating data back properly. This will provide you with the chance to create your results simpler, run them a lot more faster making them parallel without any problems whatsoever.

They should not be unit examined whatsoever! The entire reason for individuals techniques would be to integrate using the outdoors world (i.e. the database). So, make certain your integration tests beat the you-know-what from individuals techniques and lets forget about the system tests.

They must be so simple that they're "clearly bug-free", anyway – and when they are not, you need to break them up in a single part that has the logic along with a dumb part which just requires a value and stays it within the database.

Remember: the aim is 100% test coverage, not 100% unit test coverage which includes all of the tests: unit, integration, functional, system, acceptance and manual.