Conditional Compilation…

Oracle has decided to add Conditional Compilation to Oracle 10g Release 2. As Bryn Llewellyn states in his white paper Conditional Compilation in Oracle Database 10g Release 2: Unusually, but for very compelling reasons, the feature has been made available in patchsets of releases of Oracle Database earlier than the one that introduced the feature. It is available in Oracle 10g Release 1 (10.1.0.4.0) and if you have the right support contract, it can even be turned on Oracle 9i (9.2.0.6).

The idea behind Conditional Compilation is, in my opinion, two (or more) fold. One way to use this is to use new code possibilities in existing packages. Packages that need to run on different versions of the database. Another way to use it, might be to add debug code to your package, which should not be run in a production environment unless there is a problem.

Now, how do you test all this code. For example using Quest CodeTester for Oracle. In CodeTester it is possible to have only one test set per piece of code. So, what if you want to test both versions of your code (or even more possible versions if you have multiple flags in your code). CodeTester relies on the existing package and it cannot read the 'hidden' code. So, if a function becomes private, due to a compiler flag being (un)set, then the test package will become invalid. So, for testing purposes you want all the programs to be visible and you want all the flags turned on that will be turned off in production.

I would like to add a helper package though, in which I can read all the compiler flags and according to the state of those flags execute a test or not. However, there is currently no possibility to enable/disable tests on this level. There is a setup procedure (and teardown) for every test, but this is a procedure that will be called before the test runs. You also have a possibility to run code before (and after) all the tests are run. What you would want is a 'before test' and an 'after test' piece of code. This way you would be able to enable/disable certain testcases depending on the state of parameters (or package variable values). Maybe this will be possible in a future version of the product.

3 thoughts on “Conditional Compilation…

  1. Hi Patrick,

    I agree that we need to support conditional compilation in Code Tester.

    But in the meantime please note that we have external initialization and cleanup for a test definition (see lower section of Customization table at test definition level).

    So actually even in today’s version of Code Tester, you can execute alter session commands and so forth. Then we will recompile the test package….hmmm, but we will recompile the program you are testing? If it is invalid. You can of course do a recompile yourself.

    So I think that you can apply CC flags today to get the desired effect. We will in the future implement some sort of UI to help do this.

    Finally, could you “cross post” this on the Code Tester forum? Then I can answer it there for other users of the tool.

    SF


  2. I agree that there is an ‘External initialization for all unit tests’ and an ‘External cleanup for all unit tests’. But this is run before and after ALL the tests. I was hoping for a before and after piece of code that can be put ‘around’ each individual testcase. That way you can include and exclude certain testcases depending on values of the CC-Flags. I don’t see that anywhere in the program. But then again, maybe I am not looking closely enough.



Leave a Reply to steven feuerstein Cancel reply

Your email address will not be published. Required fields are marked *