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
Support JSON as source for parametrized tests arguments #492
Conversation
I would like to pass this to the other maintainers cause of the dependency thing and changes in the build script |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pioneer actually has a module-info.java
and a modular build, so you need to update that if you want the build to succeed. You can find it at src/main/java/module/module-info.java
.
(package com.fasterxml.jackson.databind is declared in module com.fasterxml.jackson.databind, but module org.junitpioneer does not read it)
From just looking at the tests, this seems to be exactly what we had in mind. Good job! I think it makes sense to pursue this further. 👍🏾 |
Thanks @Michael1993, I've updated the file. The modular build is now working correctly. I've taken this a bit further, added some documentation, and did some improvements;
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks really good, I think we can merge it "soon" (modulo my very long latency). A few comments below.
Also, if I'm not missing something, this "only" addresses part of #101. The ArgumentConverter
and a source that parses inline JSON (as opposed to from a file) are also mentioned there. If we close #101, we need to open new issues for those. (If we still want to have them.)
src/main/java/org/junitpioneer/jupiter/json/JsonFileArgumentsProvider.java
Outdated
Show resolved
Hide resolved
src/test/java/org/junitpioneer/jupiter/json/JsonFileSourceArgumentsProviderTests.java
Outdated
Show resolved
Hide resolved
Thanks for the review. I've applied the feedback and have answered some of your comments. I am not in a rush (as you can see I have a long latency as well).
Indeed this solves only a part of #101, the one where data is read from a classpath resource or a file. Reading from an inline JSON would be quite trivial as well. I'll try to add it as part of this PR as well. I am not sure about the |
By the way, I forgot to mention, I watched the stream afterwards to see your thought process when reviewing this 😄 . Couldn't be there when you were doing it live |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good, but we found some things still left to do:
- whatever we decide on the issue
- support new Cartesian tests instead of the old approach
- I still need to wrap my head around Discuss approach to optional dependencies #502 (this PR currently uses Gradle's feature variants).
return JacksonJsonConverter.getConverter(); | ||
} | ||
|
||
throw new PreconditionViolationException("There is no available Json parsing library"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This error case comes up when users haven't configured a (supported) JSON parse, so we need to make sure, it's visible. Both Maven and Gradle will cut the error message very short, so it's unclear what the problem is.
Some options:
- throw
NoJsonParserConfiguredException
(extendsPreconditionViolationException
) - print to
System.err
- log a report entry with JUnit Jupiter
We should also mention which parsers we support.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which Maven did you use? Using 3.8.4 I get
[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.031 s <<< FAILURE! - in org.junitpioneer.demo.JsonSourceTests
[ERROR] org.junitpioneer.demo.JsonSourceTests.jsonTest(String, int) Time elapsed: 0.001 s <<< ERROR!
org.junit.platform.commons.PreconditionViolationException: There is no available Json parsing library
Nothing is cut short. I will add more information about which json parsers are currently supported.
For gradle when I do ./gradlew test
I only get that test failed. In the test report you can see the full error with its stacktrace.
When I add
tasks.named<Test>("test") {
useJUnitPlatform()
testLogging {
setExceptionFormat("full")
}
}
then I get
JsonSourceTests > jsonTest(String, int) > org.junitpioneer.demo.JsonSourceTests.initializationError FAILED
org.junit.platform.commons.PreconditionViolationException: There is no available Json parsing library
at app//org.junitpioneer.jupiter.json.JsonConverterProvider.getJsonConverter(JsonConverterProvider.java:35)
.... There is actually more stacktrace
Regarding the options you mentioned:
- What is the benefit of throwing
NoJsonParserConfiguredException
? - I am not a fan of printing to
System.err
. So will leave it to you to add it in case you really really want it - I can log a report entry with JUnit Jupiter, need to see how to do that first.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't recall the details any more (stupid me, I should've added what I saw as text or screenshot), so I'll rely on your analysis. Regarding the options:
- The exception name showed up prominently - if that's
NoJsonParserConfiguredException
, it might not even be necessary to read the text. - Me neither, let's not do it then.
- you know what, ignore that. I think it makes sense to limit report entries to (mostly) successful operations, not for situations that abort the test run.
I have added a comment in that linked issue;
This is already done in this PR
This was resolved Still to do is the last comment in #492 (comment) and rebase the branch to fix the commits |
…asses for the basic functionality
… the supported libraries
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks really good. The documentation doesn't reflect the three annotations yet (I only updated the intro up until the bullet point list), but otherwise this looks good to merge. 👍🏾
src/test/java/org/junitpioneer/jupiter/ReportEntryExtensionTests.java
Outdated
Show resolved
Hide resolved
/** | ||
* Tests for {@link JsonClasspathSourceArgumentsProvider} | ||
*/ | ||
class JsonClasspathSourceArgumentsProviderTests { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No tests for files? Too brittle?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you have an idea for how we can test files in an annotation (which doesn't accept dynamic input) then I am all ears and ready to do it. Currently I am not sure how I can test this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should work, right?
@ParameterizedTest
@JsonFileSource("build/resources/test/org/junitpioneer/jupiter/json/jedis.json")
void deconstructCustomerMultipleLinesComplexType(@Property("name") String name, @Property("height") int height) {
assertThat(Collections.singleton(tuple(name, height)))
.containsAnyOf(tuple("Luke", 172), tuple("Yoda", 66));
}
I just noticed that the module declaration (in |
What is missing in the documentation? I think that we have all the info there.
What needs to be updated there? We require static (optional) access to |
I closed this by accident. I've added some replies to your comments. And I fixed some of the problems that you found. Let me know what you think. I've also added myself to the contributors list to this list, I hope I didn't mess this up. |
It still uses the old-style
Nope, looks good. And you definitely belong there for this 12-month-juggernaut. :D
Nothing, looks good. 😬 |
I've updated the documentation. It was a good thing to mention the use of proper compilable demo, because even the test annotation had a typo. I think everything is covered now, if there is something more missing, please do let me know |
Commit message:
|
Great job, @filiphr, and big thanks for your patience! |
Thanks for merging this @nipafx. It was fun working on this, it doesn't matter how long it took :) |
This is an initial implementation fro #101. It currently only supports Jackson 2 for Json Parsing. However, it should be fairly simple to add support for different parsers.
I know the policy about no runtime dependencies. Therefore, I tried using Optional Dependencies from Gradle and its feature variants. If this is something interesting we can look into doing this with different source sets in order for complete isolation (currently the Checkstyle import-control is handling this).
There is still documentation missing. However, if you like the approach I will work on the documentation.
Proposed commit message:
PR checklist
The following checklist shall help the PR's author, the reviewers and maintainers to ensure the quality of this project.
It is based on our contributors guidelines, especially the "writing code" section.
It shall help to check for completion of the listed points.
If a point does not apply to the given PR's changes, the corresponding entry can be simply marked as done.
Documentation (general)
.adoc
file in thedocs
folder, e.g.docs/report-entries.adoc
.adoc
files)Documentation (new extension)
docs/docs-nav.yml
navigation has an entry for the new extensionpackage-info.java
contains information about the new extensionCode
Contributing
README.md
mentions the new contribution (real name optional)I hereby agree to the terms of the JUnit Pioneer Contributor License Agreement.