Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parameter drive tests #151

Open
jgebal opened this issue Jan 10, 2017 · 9 comments
Open

Parameter drive tests #151

jgebal opened this issue Jan 10, 2017 · 9 comments

Comments

@jgebal
Copy link
Member

jgebal commented Jan 10, 2017

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

@Pazus
Copy link
Member

Pazus commented 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.

@mathewbutler
Copy link

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.

@alesana-san
Copy link

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 :)

@Pazus
Copy link
Member

Pazus commented Sep 5, 2019

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

@jfluri
Copy link

jfluri commented 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...

@marko-granzin-ais
Copy link

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

@lwasylow
Copy link
Member

lwasylow commented May 4, 2022

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.

@lwasylow
Copy link
Member

lwasylow commented May 8, 2022

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 ?

@jgebal
Copy link
Member Author

jgebal commented May 9, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants