1

Background -

I have a client that has an Oracle database with many procedures and functions that contain business logic. As a "good" developer, I like to have all my business logic have automated tests wrapped around it.

The procedure in question is very long with nested ifs. It hits many tables and views based on data passed in and data retrieved from the database.

My initial thought is to create a c# application containing only NUnit tests that will use data already in the database to test the procedure. Once I have 100% code coverage, I will modify those tests to insert/cleanup the test data. Once that is done, I can then refactor and modify the procedure as needed without worry of breaking something.

Is there a better/easier way to do automated testing for Oracle procedures/packages/functions?

EDIT: I cannot use something that needs to be installed on the server at this point.

Michael Wheeler
  • 2,459
  • 3
  • 19
  • 26

2 Answers2

1

You could use one of the already mentioned PL/SQL targeted testing frameworks - which is probably the easiest solution to your problem.

If you really want to roll your own solution, PL/SQL procs/functions are easily callable from .NET, so you could just use xUnit as a runner:

  • The key really is to make sure you are able to setup a specific known input scenario for each test. You can roll your own approach to this solution (sql scripts, custom configuration files, create the data in code), or use an existing framework targeted at resetting your database to an initial known state specific for each test (something like NDbUnit).

  • Write a small wrapper library that allows you to call your procedures easily to make tests more readable and concise.

  • To make sure your tests do not leave traces behind and you get caught up in test dependencies and ordering problems, you can use transactions as part of your tests - start a transaction in the [SetUp] method, rollback on [TearDown].

tjdecke
  • 567
  • 4
  • 11
0

There is a unit testing framework for PL/SQL utPLSQL that you may be able to use to do all you testing inside the database.

GrahamA
  • 5,875
  • 29
  • 39
  • Thanks for the answer. I have now looked at this and cannot use something that has to install on the server. I have edited my question with that information. – Michael Wheeler Nov 02 '11 at 13:49