-
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
[Discussion] Implementation of statically typed data providers #2154
base: master
Are you sure you want to change the base?
[Discussion] Implementation of statically typed data providers #2154
Conversation
Interesting idea :-) I think I would approach this a different way, maybe with an annotation processor that would generate code that only compiles if the types match. Just thinking out loud, haven't really given this much thought. |
@korobochka I've already concerned this before (when TestNG hasn't even migrated to Java 8). You can check test-data-supplier 3rd-party extension, which I've created to reduce DP pain. Note that it works with Java 11 modular apps as well. Moreover, there's an IntelliJ IDEA plugin for syntax highlight and basic navigation. P.S. I don't believe it could be ever migrated to the current TestNG codebase due to additional dependencies and Java version differences. |
@sskorol Your library looks good, but is solves a bit different problem (conveniently return Streams/Lists/other things) from the Data Provider. It still does not make sure (in compile time) that the types returned match test arguments. |
@korobochka - Thinking loud.. What if we enhanced TestNG such that, this can reside outside of TestNG and when plugged in, TestNG would basically just invoke the customisation ? That way people would be able to wire in their way of dealing with statically typed data providers (today its byte code manipulation, tomorrow it could be something else). Do you think we could just take this to that direction ? |
@korobochka I see your point now. What if we delegate this task to an IntelliJ plugin? At least developers will see highlighted areas on-fly, before compilation. Would it resolve your initial issue? |
The idea is good but like @krmahadevan I think it should be provided in a 3rd party project. But does TestNG provide an easy enough SPI for the injection of test parameters? For the record, what is provided by JUnit5: https://blog.codefx.org/libraries/junit-5-parameterized-tests/ |
Hi!
I've always felt a bit "dirty" creating lots of Object[][] in data providers, and also sometimes wrong types get passed around leading to (somewhat) obscure runtime errors.
In this PR is the possible implementation of statically typed data providers, example of usage looks like this:
Current implementation is by no means final, but I wanted to start a discussion about this, and if TestNG even needs such API.
However, this implementation works already.
Pros:
Cons:
What do you think? Would such API be useful for TestNG users? Maybe the same can be implemented better / in a different way?
Did you remember to?
CHANGES.txt
(not needed for now)