I’m working on a project with a lot of plsql code and would like to add more specific unit-tests to our codebase. Some of the procedures/functions I like to test aren’t in the package spec and I have no means to change that.
Is there a way to access these ‘private’ plsql procedures without adding them to the spec?
The only Idea I had so far, was to compile a special package spec to the DB before the tests, that specifies the procedures under test. I gues that would work, but I wonder if there is a simpler way, some evil secret oracle hack maybe 😉
I’m testing from Java with JUnit/DBUnit.
BR
Frank
There is a way to do this, providing you are on 10g or higher. It’s called Conditional Compilation. This is a highly neat feature which provides special syntax so we can change our PL/SQL code at compilation time.
As it happens I have been using this feature precisely to expose private packages in a spec so I can run UTPLSQL tests against them.
Here is the special syntax:
That variable with the double-dollar sign is a Conditional Compilation flag.
If I describe the package we can only see the public package:
Now I set the conditional flag and re-compile the package, and as if by magic …
Privatising the functions is as simple as you think it would be:
We can do lots more with conditional compilation. It’s covered in the docs. Find out more.