-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Add support for record classes in data providers #2241
Comments
@mcimadamore Did you try it? What was the issue? |
I did not try - note that it will require changes to the testng data provider mechanism so that it will support record types natively. In other words, the above describes a possible suggestion for an enhancement to the testng framework to take advantage of some of the newer Java features. |
Data providers accept Iterators and I don't see why it can't work with an iterator of records. |
If I'm not mistaken, the Iterator support currently goes like
While Iterator<Object[]> is slightly better than Object[][], you still have the problems described in my original issue:
The solution I've sketched uses a record - which you can think of as a named tuple - to model the Object[] part of the data provider (that is, the set of arguments to be passed to a single test method call). So, if
a data provider could return either:
Then your test can still be something like:
Much easier to see if the data provider agrees with the test method, and also easy for testNG to reflectively unpack the record |
It would be nice if testng supported the newly added records feature, as a means to replace Object arrays in data providers. Record types [1] are simple data carriers, which can contain any data. They are better suited at modelling parameter lists than Object[] for a number of reasons:
This would enable not only test writers to write better code, but also for the testng framework to become more robust (since testng could cross-validate the record component types against the parameter types of a given test method using a data provider). Similarly, IDEs could take advantage of the added type safety and highlight mismatches between data providers and tests.
Expected behavior
Actual behavior
[1] - https://openjdk.java.net/jeps/359
The text was updated successfully, but these errors were encountered: