Hello. I'm Steven Feuerstein, Oracle PL/SQL evangelist for Dell software, and today I'm going to show you how to dynamically generate test cases using Code Tester for Oracle, a powerful automated testing tool for PL/SQL programmers. Dynamic test case generation is important when you want to cover lots of different scenarios without having to write them all yourself individually.
So let's take a look. I'm going to work with a very simple program called Between String. It's actually a variation on substring, in which I pass the string, the start and the end locations, whether or not I want to include the endpoints, and it returns the string between those two points.
I've already created a test definition testing for a variety of different conditions. This is my regression test. And one of my tests is called an null start location always returns null-- in other words, when I call this program, if I pass a null for start, then no matter what I pass in for string_in or end_in, I should always get a null value back.
And I've run my test, and so far it looks pretty good. So null start location always returns null. I pass inclusive_true and it has a not null value, string has a not null value, but I pass in a start value of null, and look-- it comes back null. Great, it worked.
But that's just one combination of values. What if I want to test lots of different combinations of values-- long strings, small strings, big numbers, small numbers? Well, it would be awfully tedious to have to write those all yourself, so instead I'm going to take advantage of dynamic test case generation.
I'm going to go to my null start location always should return null, and notice I've got my hard coded literal values. What I'm going to do, though, is go down to the bottom of my window and click on the multiple values pop up. And now I can specify random values, lists of values, queries, et cetera, so I'm going to say that I want five different strings-- minimum length five, maximum length 1,000.
I can choose the type of characters I want to use, I can test my randomization-- yeah, looks pretty random. Press OK.
Then I'm going to go to my END_IN. And now I could also do random value generation here, but instead I'll just show you a variation, which is I can create a query that will be used to populate this argument dynamically at run time. So select employee_id from employees where rownum less than six. Test my query-- there are five values. Great-- so in other words, you can have data in a table to drive your tests.
Save that. I'm going to one more thing. I can either correlate or permutate values between my different groups of multiple values. In this case, I definitely want permutation. So I make that selection, click on Run, and now what will happen is that when I take a look at the results, which are still, valid, notice I've got 25 generated test cases, all with different combinations of values.
There's my dynamic string, my dynamic END_IN, and I didn't have to do any of the work of manually creating these things. So now I've got a much higher level of confidence that this program really will return null no matter what I throw at it for strings and numbers in those two different arguments.
And of course, you could create another test case, an entirely different test definition, besides this regression test in which I specify, say, 100 strings and 100 different numbers, which leads to lots and lots of test cases. And then you can run that kind of test overnight as part of a batch job because it will take quite a while. But again, you'll get a very strong level of confidence about the quality of your code.
Well, I hope this gives you a good sense about some of the dynamic test generation features in Code Tester and some of the more advanced features of what you can do when you're building automated regression testing. For more information about Code Tester for Oracle and the entire Toad for Oracle development suite of which it's a part, visit quest.com/Toad-Development-Suite-for-Oracle, and happy PL/SQL coding and testing.