Repository navigation
Parameter drive tests #1326
Unanswered jgebal asked this question in Feature Requests Parameter drive tests #1326Uh oh!
There was an error while loading. Please reload this page.
{{title}}
Something went wrong.Uh oh!
There was an error while loading. Please reload this page.
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: Here are examples of different ways to use it. |
Replies: 11 comments · 19 replies
Comment optionsUh oh!
There was an error while loading. Please reload this page.
{{title}}
Something went wrong.Uh oh!
There was an error while loading. Please reload this page.
Pazus
Apr 18, 2018
We can call it providing parameter values by iterating over sql statement using 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. |
Uh oh!
There was an error while loading. Please reload this page.
{{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;
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. |
Uh oh!
There was an error while loading. Please reload this page.
{{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
No offense, guys, just thoughts out of my head :) |
Uh oh!
There was an error while loading. Please reload this page.
{{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: |
Uh oh!
There was an error while loading. Please reload this page.
{{title}}
Something went wrong.Uh oh!
There was an error while loading. Please reload this page.
jfluri
Jun 16, 2020
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... |
Uh oh!
There was an error while loading. Please reload this page.
{{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 .... |
Uh oh!
There was an error while loading. Please reload this page.
{{title}}
Something went wrong.Uh oh!
There was an error while loading. Please reload this page.
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 --%parameterizedtest
--%valuesource{"Test"}
procedure testme(a_displayname in varchar2);
result in : or --%parameterizedtest
--%valuesource{"Test,10"}
procedure testme(a_displayname in varchar2, a_beer_count in number);
result in : 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 : 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. Personally if we would to implement this I would suggest stick to basic datatypes. |
Uh oh!
There was an error while loading. Please reload this page.
{{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 |
Uh oh!
There was an error while loading. Please reload this page.
{{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. I think we should consider using DB tables for storing and reading parameters. |
Uh oh!
There was an error while loading. Please reload this page.
{{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. |
Uh oh!
There was an error while loading. Please reload this page.
{{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:
|
| 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, packageut_test_case_values. --%testcasecases are cached like normal tests.--%testcasesourcecases 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
- Annotation names:
--%testcase/--%testcasesource, or JUnit-like names such as--%parameterizedtest/--%valuesource(as suggested earlier in this thread)? - Is the placeholder syntax
{1}/{name}fine? - Should
--%testcasesourcebe part of the first version, or come as a second step? - Snapshot semantics for the source query (read once) instead of re-querying per case: OK?
- 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), sopkg.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?
Uh oh!
There was an error while loading. Please reload this page.
{{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 If that is the case, I am happy to draft a PR. |
Uh oh!
There was an error while loading. Please reload this page.
{{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}
]
|
Uh oh!
There was an error while loading. Please reload this page.
{{title}}
Something went wrong.Uh oh!
There was an error while loading. Please reload this page.
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. |
Uh oh!
There was an error while loading. Please reload this page.
{{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! |
Uh oh!
There was an error while loading. Please reload this page.
{{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. |
Uh oh!
There was an error while loading. Please reload this page.
{{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
Each test case is reported as its own test ( --%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,
JSON values are converted to the parameter types:
A value that can't be converted only makes its own test case error, e.g.
Questions
If that all works for you, I'll open the PR. |
Uh oh!
There was an error while loading. Please reload this page.
{{title}}
Something went wrong.Uh oh!
There was an error while loading. Please reload this page.
jgebal Nov 27, 2026 Maintainer Author
|
@WayneNani I read through it and it triggered some more thoughts.
|
Uh oh!
There was an error while loading. Please reload this page.
{{title}}
Something went wrong.Uh oh!
There was an error while loading. Please reload this page.
jgebal Nov 27, 2026 Maintainer Author
Uh oh!
There was an error while loading. Please reload this page.
{{title}}
Something went wrong.Uh oh!
There was an error while loading. Please reload this page.
PhilippSalvisberg Nov 27, 2026 Collaborator
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. |
Uh oh!
There was an error while loading. Please reload this page.
{{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.
That means, the function you specify in I will implement the other requests as well. |
Uh oh!
There was an error while loading. Please reload this page.
{{title}}
Something went wrong.Uh oh!
There was an error while loading. Please reload this page.
jgebal Dec 1, 2026 Maintainer Author
|
I am also expecting a solution where both 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. Making sure that the 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 |
This discussion was converted from issue #151 on May 09, 2026 17:01.
Heading Bold Italic Quote Code LinkNumbered list Unordered list Task list
Attach files Mention Reference Menu
Select a reply
LoadingUh 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