DAGDA SEARCH | Back to results | Support the Project

Parameter drive tests · utPLSQL/utPLSQL · Discussion #1326 · GitHub

Source: https://github.com/utPLSQL/utPLSQL/discussions/1326

Repository navigation

Parameter drive tests #1326

Unanswered jgebal asked this question in Feature Requests Parameter drive tests #1326 @jgebal jgebal Jan 10, 2017 · 11 comments · 19 replies Return to top Discussion options

{{title}}

Something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

{{editor}}'s edit

{{actor}} deleted this content .

{{editor}}'s edit

Something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

jgebal Jan 10, 2017 Maintainer

There is an interesting extension to JUnit:
https://github.com/Pragmatists/JUnitParams
We could think of implementing something similar.

Here are examples of different ways to use it.
https://github.com/Pragmatists/JUnitParams/blob/master/src/test/java/junitparams/usage/SamplesOfUsageTest.java

You must be logged in to vote All reactions

Replies: 11 comments · 19 replies

Comment options

{{title}}

Something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Pazus Apr 18, 2018

—%test
—%parametrized(select name, birthdate from test_clients)
procedure tst_client_proc(a_name varchar2, a_birthdate date);

We can call it providing parameter values by iterating over sql statement using dbms_sql

We can also accept a function which returns a cursor.

Parameters should be mapped by name if the column aliases in the query correspond equally or by position if not.

You must be logged in to vote All reactions 0 replies Comment options

{{title}}

Something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

mathewbutler Apr 18, 2018

Does this need to support query input? The model I have in mind is;

  • a data setup step
  • parameterised annotation passing list of items set up in data (without SQL)

With this you have the same capability, just without exposing SQL to the annotation.

My concern is opening up avenue of issues where users want to persist test / results data to drive tests rather that keep tests isolated and UtPLSQL clean from data storage.

You must be logged in to vote All reactions 0 replies Comment options

{{title}}

Something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

alesana-san Dec 19, 2018

I agree with @mathewbutler. I guess the better option is to preset all test data (like test_clients) and then iterate over it in a single test and check the results. Given that we have:

  • Knowing that ut.expect doesn't stop execution after the first fail we will iterate through all given data;
  • We don't have tons of test executions in reports about every single launch of iterated test but still keep data about all fails;
  • I think that inventing a new annotation should provide some sort of a utility but we just take parametrizing (params, query or whatever) out of the test body and put it in a declaration part. Instead test-writer can do it by himself feeling free to write any kind of query and handle it in a way he wants it inside of the test body.

No offense, guys, just thoughts out of my head :)

You must be logged in to vote All reactions 0 replies Comment options

{{title}}

Something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Pazus Sep 5, 2019

We should look at something like this:
https://junit.org/junit5/docs/current/user-guide/#writing-tests-parameterized-tests

You must be logged in to vote All reactions 0 replies Comment options

{{title}}

Something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

jfluri Jun 16, 2020

We should look at something like this:
https://junit.org/junit5/docs/current/user-guide/#writing-tests-parameterized-tests

I like the Functionality that the @MethodSource annotation in jUnit has. It provides a Stream of (multiple) parameters that are handed to the test executions. Like a rowtype in a way...

You must be logged in to vote All reactions 0 replies Comment options

{{title}}

Something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

marko-granzin-ais May 4, 2022

I think there must be some kind of cursor as parameter ... so i can enter all i like - i hope you implemet this soon ....

You must be logged in to vote All reactions 0 replies Comment options

{{title}}

Something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

{{editor}}'s edit

{{actor}} deleted this content .

{{editor}}'s edit

Something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

lwasylow May 4, 2022 Collaborator

I think we could approach that problem with a new annotation to imitate an above junit5 approach.

--%parameterizedtest
--%valuesource{"Test"}
procedure testme(a_displayname in varchar2);

result in :
Test was expected to be called Test

or

--%parameterizedtest
--%valuesource{"Test,10"}
procedure testme(a_displayname in varchar2, a_beer_count in number);

result in :
Test was expected to be called Testand had a 10 beers

or

--%parameterizedtest
--%valuesource{"Test,10":"Test2,5"}
procedure testme(a_displayname in varchar2, a_beer_count in number);

as alternative we could use a different annotation for multiple parameters so the code is more readable. e.g.

--%parameterizedtest
--%valuesource{"Test,10"}
--%valuesource{"Test2,5"}
procedure testme(a_displayname in varchar2, a_beer_count in number);

result in :
Test was expected to be called Testand had a 10 beers
Test was expected to be called Test2,5and had a 5 beers

The value source would be a colon separated inputs with list of coma separated values hat would have to be ordered in same way parameters in procedure each parameter entry as an annotation entry one below the other.
The valuesource would be iterated over list of values.
This would not solve the problem of complex types and to be fair not sure how to approach as the complexity is infinite here.
I can see maybe using a datatype information as junit5 to cast to datatype e.g.--%valuesource{"test.test_type=Test"} but there are nested types, types that are not part of tested schema ( so extra grants complexity ).

Personally if we would to implement this I would suggest stick to basic datatypes.

You must be logged in to vote All reactions 0 replies Comment options

{{title}}

Something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

lwasylow May 8, 2022 Collaborator

Actually I take it back. We could try to write a tests with anydata and let the user define a logic to handle the type inside tests.
What you think about it @jgebal and above suggestions ?

You must be logged in to vote All reactions 0 replies Comment options

{{title}}

Something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

jgebal May 9, 2022 Maintainer Author

I think it would be good to do a full review of what JUnit is proposing for parametrized tests and maybe check how other testing frameworks are solving this.

In essence the key challenge is to come up with a good specification of annotations and parameters that will be relatively easy to use for average Oracle PL/SQL engineer.
Having that said, I would refrain from leveraging ANYDATA, as it's API is quite complicated and not very friendly to use.

I think we should consider using DB tables for storing and reading parameters.

You must be logged in to vote All reactions 1 reply @mathewbutler Comment options

{{title}}

Something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

mathewbutler Nov 19, 2026

"I think we should consider using DB tables for storing and reading parameters." - I'm really cautious about introducing any permanent state for reasons of table and data management (and data lifecycle). I can see how using a suitable TEMPORARY table approach might avoid some or all of what I would be concerned about though.

All reactions Comment options

{{title}}

Something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

WayneNani Nov 17, 2026 Collaborator

I'd like to pick up this discussion with a concrete design and a working prototype, and get your feedback on it.

1. Inline test cases: --%testcase

--%test(Half of {1} is {2})
--%testcase(2000, 1000)
--%testcase(a_amount => 10, a_half => 5)
procedure half(a_amount number, a_half number);
  • One annotation per case; the arguments use normal PL/SQL syntax (by position or by name, any expression).
  • Each case is a separate test named half[1], half[2], … and can be run alone: ut.run('pkg.half[2]').
  • The description can use placeholders {1}, {a_amount}; without placeholders the arguments are appended.
  • Arguments are checked when the suite is built (count, names, missing parameters without defaults, overloads). An invalid case gives a warning and is skipped. Types are not checked; a wrong type makes that one test case error when it runs.

2. Test cases from a query: --%testcasesource

This follows the idea of keeping (complex) test data in tables:

--%test(Bulk discount for {label} is {a_expected})
--%testcasesource(select label, a_lines, a_expected from test_bulk_discount_cases order by label)
procedure bulk_discount(a_lines order_lines, a_expected number);
  • The query runs once, after --%beforeall, so it sees the data that beforeall creates.
  • Columns named like parameters are passed by name; if none matches, all columns are passed by position. Other columns can be used in the description.
  • Values keep their type: scalars, LOBs, RAW, intervals, object types and collections, BOOLEAN on 23+. Internally they are transported as ANYDATA, but users never see ANYDATA. Unsupported types (XMLTYPE, JSON, …) give a clear error.
  • Values are read as a snapshot, so changes to the data in beforeeach/beforetest don't affect later cases.
  • No rows → warning; query error → test reported as errored; a disabled test doesn't run its query.

3. Arguments for before/after procedures (#1328)

--%beforetest(log_call('a, b', 1), log_call(a_text => 'x', a_number => 2))

This uses the same argument parsing and call mechanism, so it comes almost for free.

Comparison with JUnit 5

JUnit 5 Proposal
@ParameterizedTest + @CsvSource / @ValueSource --%testcase(...)
@MethodSource --%testcasesource(select ...)
name = "{0} …" description placeholders {1}, {name}

Unlike CSV sources, the arguments are real PL/SQL expressions, so dates, object constructors etc. work without conversion.

Compatibility

  • No change for existing tests.
  • New internal objects: type ut_anydata_list, package ut_test_case_values.
  • --%testcase cases are cached like normal tests. --%testcasesource cases are only known at runtime, so reporters that list tests up front (e.g. realtime) list such a test once.

I built a prototype on https://github.com/WayneNani/utPLSQL/tree/feature/parameterized_tests
It includes tests and user documentation (annotations.md). The full suite passes on 23ai Free and 21c. 19c is not verified yet.

Full disclosure:: This is a feature that I could use in a project I have at the moment and so I asked Claude Opus to give it a go (as is clear from the commit history). I tested it out and it works great for my use case but I just wanted to tell you that upfront.

Questions

  1. Annotation names: --%testcase / --%testcasesource, or JUnit-like names such as --%parameterizedtest / --%valuesource (as suggested earlier in this thread)?
  2. Is the placeholder syntax {1} / {name} fine?
  3. Should --%testcasesource be part of the first version, or come as a second step?
  4. Snapshot semantics for the source query (read once) instead of re-querying per case: OK?
  5. Running a single test case by path works for --%testcase (ut.run('pkg.half[2]')), but not for --%testcasesource, because its rows are only known at runtime (after beforeall), so pkg.half_from_table[2] is not found in the suite cache (ORA-20204). It could be supported by resolving such a path to the base test and running only row n. Is that needed in the first version?
You must be logged in to vote All reactions 13 replies @WayneNani Comment options

{{title}}

Something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

WayneNani Nov 25, 2026 Collaborator

@jgebal I would be interested in opeing a PR. But I would like to finalize the design with you first. I like the JSON approach as it should be familiar to most developers. But it has its weaknesses, as @mathewbutler pointed out. We could no longer allow sysdate, package constants etc. directly within the --%testcase comment. Are you fine with pushing these into functions returing JSON?

If that is the case, I am happy to draft a PR.

All reactions @jgebal Comment options

{{title}}

Something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

jgebal Nov 25, 2026 Maintainer Author

The SYSDATE/ SYSTIMESTAMP could be achieved in JSON easily with SQL.

  function discount_cases return clob is
    l_result clob;
  begin
    select json_array(
             json_array(500,  'REGULAR', sysdate,
                        cast(systimestamp - interval '14' day as timestamp), systimestamp + interval '16' day, 0.05),
             json_array(1000, 'REGULAR', sysdate + 30,
                        cast(systimestamp - interval '14' day as timestamp), systimestamp + interval '16' day, 0.1),
             json_object(
               'a_order_total'   value 50,
               'a_customer_type' value 'VIP',
               'a_order_date'    value sysdate - 5,
               'a_promo_start'   value cast(systimestamp - interval '14' day as timestamp),
               'a_promo_end'     value (systimestamp + interval '16' day) at time zone '-05:00',
               'a_expected'      value 0.25
             ),
             json_object(
               'a_order_total'   value null,
               'a_customer_type' value 'REGULAR',
               'a_order_date'    value sysdate - 20,
               'a_promo_start'   value cast(systimestamp - interval '14' day as timestamp),
               'a_promo_end'     value systimestamp + interval '16' day,
               'a_expected'      value 0
             )
             returning clob
           )
      into l_result
      from dual;
    return l_result;
  end;

returns:

[
  [500, "REGULAR", "2026-11-25T10:15:42", "2026-11-11T10:15:42.123456", "2026-12-11T10:15:42.123456+02:00", 0.05],
  [1000, "REGULAR", "2026-12-25T10:15:42", "2026-11-11T10:15:42.123456", "2026-12-11T10:15:42.123456+02:00", 0.1],
  {"a_order_total": 50, "a_customer_type": "VIP", "a_order_date": "2026-11-20T10:15:42", "a_promo_start": "2026-11-11T10:15:42.123456", "a_promo_end": "2026-12-11T03:15:42.123456-05:00", "a_expected": 0.25},
  {"a_order_total": null, "a_customer_type": "REGULAR", "a_order_date": "2026-11-05T10:15:42", "a_promo_start": "2026-11-11T10:15:42.123456", "a_promo_end": "2026-12-11T10:15:42.123456+02:00", "a_expected": 0}
]
All reactions @jgebal Comment options

{{title}}

Something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

{{editor}}'s edit

{{actor}} deleted this content .

{{editor}}'s edit

Something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

jgebal Nov 25, 2026 Maintainer Author

Since it's a big change, I'd prefer to have it as a PR from a branch inside the repo so all the checks can run automatically.
@WayneNani - I can add you as contributor to utPLSQL so you can work on feature branch directly in the repository.
Let me know if it's good for you.
In that case I could also add some contributions to the PR directly instead of limiting myself to comments.

All reactions @WayneNani Comment options

{{title}}

Something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

WayneNani Nov 25, 2026 Collaborator

@jgebal That works for me!

All reactions @jgebal Comment options

{{title}}

Something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

jgebal Nov 25, 2026 Maintainer Author

@WayneNani - you should be able to push the feature branch directly into utPLSQL repo.
You may also want to join the community.utplsql.org
Is is a replacement for our previous SLACK platform.

All reactions Comment options

{{title}}

Something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

WayneNani Nov 26, 2026 Collaborator

@jgebal I've pushed the feature to feature/json_test_cases (sorry for the noise...). As you suggested, --%testcase now takes JSON only: an array passes the values by position, an object by parameter name (keys aren't case-sensitive). sysdate, constants etc. come from a --%testcasesource function returning json_array_t or sys_refcursor. The user guide is in annotations.md.

  1. Placeholders in the description

Each test case is reported as its own test (proc[1], proc[2], …). The --%test description can refer to its values:

--%test(Half of {a_amount} is {a_half})   -- by name
--%test(Half of {1} is {2})               -- by position
--%test(Half)                             -- no placeholder: values are appended, "Half (4, 2)"

For a cursor, {name} can also refer to a column that isn't passed to the procedure, e.g. {label}.

  1. Type conversion

JSON values are converted to the parameter types:

Parameter type JSON value
NUMBER, BINARY_FLOAT/DOUBLE number, or a string with a number ("0.05")
VARCHAR2, CHAR, CLOB (also national) string (a number is converted)
BOOLEAN true / false
DATE, TIMESTAMP (with (local) time zone) ISO 8601 string, independent of NLS settings
INTERVAL ISO 8601 duration ("P1DT2H") or Oracle interval string
RAW hex string
object type JSON object with all attributes as keys, e.g. {"amount": 8, "half": 4}
collection (nested table, varray) JSON array, e.g. [1, 2, 3]

A value that can't be converted only makes its own test case error, e.g. "abc" for a NUMBER, an object with a missing attribute, or a scalar for an object type (json_value would silently create an object with all attributes null there). BLOB, XMLTYPE, records and PL/SQL-only collections can't be passed from JSON.

  1. Error handling
  • An invalid --%testcase (not JSON, too many values, unknown key, missing parameter without default) gives a warning when the suite is built and is skipped. The numbers of the other cases don't change.
  • An unknown JSON key is an error, not ignored, so a typo doesn't silently leave a parameter at its default.
  • For cursors, I followed @PhilippSalvisberg's suggestion: columns are bound by name, and the error names the column or parameter, e.g. when a parameter without default has no column, two columns map to the same parameter, or an object/BOOLEAN column doesn't fit. A column that matches no parameter is only allowed if the description uses it as a placeholder, so a misspelled alias doesn't go unnoticed.

Questions

  1. If no column is named like a parameter, the columns are passed by position, but only if their number equals the number of parameters, even if the remaining parameters have defaults. I made this strict on purpose, as the fallback is implicit. It can still be relaxed later. Is that OK?
  2. The source function is called once after --%beforeall, and its result is used as a snapshot. Fine?
  3. Overloaded test procedures aren't supported with test cases, and running a single case by path (pkg.proc[2]) only works for --%testcase. OK for the first version?

If that all works for you, I'll open the PR.

You must be logged in to vote All reactions 5 replies @jgebal Comment options

{{title}}

Something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

jgebal Nov 27, 2026 Maintainer Author

@WayneNani
Thanks for the detailed information.

I read through it and it triggered some more thoughts.

json_array_t not cursor to return --%testcasesource function

There are few reasons for that:

  1. Providing cursor as an option may easily lead to generation of countless test-case. As it will be super-easy to do, developers may be tempted to cover all possible test cases instead of focusing on explicitly covering all branches of logic. Framework should provide tools that encourage good practices and discourage malpractices.
  2. Using cursors introduces a problem of interpretation between positional and named parameters. This is automatically handled in JSON result set by returning a JSON ARRAY containing JSON ARRAY or JSON OBJECT.
  3. If needed, developers can still use SQL to generate JSON ARRAY and return that back as a result set. The side effects of this should also be documented as the function may no longer me deterministic and idempotent when using SQL or build-in functions (SYSDATE etc.)

test cases generation time

There are functions in utPLSQL that allow users to see the full test suite hierarchy without running the test suite ut_runner.get_suites_info. I assume that this is still working well?

Also ut_runner.is_test should work fine.

Error handling

  • Failing a whole suite run because one testcase or testcasesource is misconfigured would be a bad idea and should not happen.
  • All rows (array element) from testcasesource and all testcase should be counted as tests even if the call parameters to test are invalid.
  • Extra elements in JSON OBJECT or JSON ARRAY for testcase (testcasesource item), should be permitted and should not cause any errors. This will allow the testcasesource function to be reused for more than one test. Flexibility is good as long as it doesn't bring ambiguity. So I vote against the suggestion: An unknown JSON key is an error, not ignored, so a typo doesn't silently leave a parameter at its default.
  • A testcase (testcasesource item) with badly defined parameters should not be ignored but reported as an erroring test because the testcase could not be executed (missing parameters or incorrect datatypes). This is consistent with behaviour where a test throws unhandled exception or scenario where a valid test suite package body fails to compile.
  • We need to assure protection against SQL injection when passing parameters to before/after/test procedures.
  • Invalid reference to testcase parameter in test description should not cause test execution failure. So a testcase --%test(Not existing {reference}) should be reported at runtime using the fallback mechanism --%test(Not existing {reference}) --no placeholder: values are appended, "Not existing {reference} (4, 2)"
  • Some edge cases to be tested and handled. A test procedure without parameters that has testcases - errors the testcases

Questions:

  • Do we allow duplicated testcase (testcasesource item) values so you can have several identical test runs or do we do distinct?

Summary

I do not understand the question so I didn't answer it.

  1. The source function is called once after --%beforeall, and its result is used as a snapshot. Fine?

As for the rest I hope that what I wrote explains more about how I see things.

Happy to her from you.

All reactions @jgebal Comment options

{{title}}

Something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

jgebal Nov 27, 2026 Maintainer Author

@PhilippSalvisberg @mathewbutler @lwasylow

All reactions @PhilippSalvisberg Comment options

{{title}}

Something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

PhilippSalvisberg Nov 27, 2026 Collaborator

There are functions in utPLSQL that allow users to see the full test suite hierarchy without running the test suite

In JUnit Jupiter, the parametrised test method is discoverable before execution, and its individual invocations are registered during the run. From the test results, I can rerun just one invocation, which I do a lot when debugging.

I’d suggest following the same pattern in utPLSQL. Show the parametrised test in the suite hierarchy, report each invocation separately when it runs, and let users rerun a single invocation.

All reactions @WayneNani Comment options

{{title}}

Something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

WayneNani Nov 28, 2026 Collaborator

@jgebal Happy to implement the changes!

I think, that we can allow duplicate test runs. I don't see harm in that.

Regarding throwing an error on non-matching elements in the JSON: My thinking was that you should notice when you did a typo. Otherwise, the test might silently use the default value from the parameter you are missing. But I do see your point with reusing functions for multiple tests.

  1. The source function is called once after --%beforeall, and its result is used as a snapshot. Fine?

That means, the function you specify in --%testcasesource is run after the --%beforeall. This way, --%beforeall could setup something for the function to query etc. This would mean that these are not discoverable before the run. --%testcase is discoverable before the run with get_suites_info.

I will implement the other requests as well.

All reactions @jgebal Comment options

{{title}}

Something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

jgebal Dec 1, 2026 Maintainer Author

@WayneNani @PhilippSalvisberg

I am also expecting a solution where both --%testcase and --%testcasesource are fully discoverable before test run.

There should be no side effects like different testcase-set executed at runtime vs discovered before run.

I understant that it's tempting to allow this for more flexibility but it will definitely cause more headaches in complex setups.
Engineering tends to become complex and it's difficult to keep it simple.

Making sure that the --%testcasesource is defined before any other code is executed is assuring that the tests have no side effects which is one of fundamental rules of tests being isolated.

There can be no dependency between test execution order and test results. So a test can run by itself and it can run in a full suite.

I realise that beforeall/beforetest/beforeeach are a hard preconditions for test data setup but they should not be preconditions for defining the contents of a test suite run. Result of beforeall execution cannot impact how many tests-cases will be executed.

All reactions Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment Category 💡 Feature Requests Labels enhancement 9 participants @jgebal @mathewbutler @PhilippSalvisberg @lwasylow @jfluri @Pazus @WayneNani @alesana-san @marko-granzin-ais Converted from issue

This discussion was converted from issue #151 on May 09, 2026 17:01.

Heading Bold Italic Quote Code Link
Numbered list Unordered list Task list
Attach files Mention Reference Menu

Select a reply

Loading

Uh oh!

There was an error while loading. Please reload this page.

Create a new saved reply reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji