-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Add Kotlin code examples with tabs to documentation #5316
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
base: main
Are you sure you want to change the base?
Add Kotlin code examples with tabs to documentation #5316
Conversation
✅ All tests passed ✅🏷️ Commit: 7c52015 Learn more about TestLens at testlens.app. |
marcphilipp
left a comment
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.
Thank you, looks very promising! 👍
| @ExtendWith(RandomParametersExtension::class) | ||
| class KotlinMyRandomParametersTest { | ||
|
|
||
| @Test | ||
| fun injectsInteger(@Random i: Int, @Random j: Int) { | ||
| assertNotEquals(i, j) | ||
| } | ||
|
|
||
| @Test | ||
| fun injectsDouble(@Random d: Double) { | ||
| assertEquals(0.0, d, 1.0) | ||
| } | ||
| } |
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.
Please move this snippet into a .kt file in src/test/java so it gets compiled and executed.
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.
Let's then maybe also extract the Java version of MyRandomParametersTest to a file in src/test/java? Currently it's inline in the .adoc file, and extracting only the Kotlin version would be inconsistent. I can do both.
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 missed that. Yes, we should do that as well!
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.
It seems I know why it was inlined. The Java snippet uses RandomParametersExtension which is in the junit-examples repository, not here. If extracted to a file, it won't compile. The local RandomNumberExtension also only supports int, not double, so injectsDouble wouldn't work either.
Options:
- Keep Java inline (as is). And probably it will be right to inline Kotlin as well, with using both injectsInteger + injectsDouble).
- Extract Java but adapt it to use local @random annotation and remove injectsDouble.
What do you prefer?
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.
TBH, I don't see any point in referencing two different "random number" extensions within our User Guide.
It's of course OK for the RandomParametersExtension to remain in the examples repository, but I think it's fine to stick with the local RandomNumberExtension in the User Guide, both in Dependency Injection for Constructors and Methods as well as in Registering Extensions.
So, I'm in favor of revising the current Java-based example to use RandomNumberExtension, and the Kotlin-based example would copy that. Perhaps demonstrating parameter resolution for the constructor and a test method would suffice -- basically like RandomNumberDemo but without the field injection.
| // tag::user_guide[] | ||
| @Execution(ExecutionMode.SAME_THREAD) |
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.
| // tag::user_guide[] | |
| @Execution(ExecutionMode.SAME_THREAD) | |
| @Execution(ExecutionMode.SAME_THREAD) | |
| // tag::user_guide[] |
...tion/modules/ROOT/pages/writing-tests/dependency-injection-for-constructors-and-methods.adoc
Outdated
Show resolved
Hide resolved
mpkorstanje
left a comment
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.
Please satisfy the DCO bot by singining off on your commits. It's best to start it early, rebasing afterwards can be painful.
f719c64 to
099a6a0
Compare
- Add @asciidoctor/tabs extension for tabbed code blocks - Add Kotlin examples for Writing Tests intro - Add Kotlin examples for Dependency Injection documentation - Add UI supplemental files (tabs.css, tabs.js) for tab styling Signed-off-by: Anton.Yalyshev <[email protected]>
Signed-off-by: Anton.Yalyshev <[email protected]>
099a6a0 to
20ba541
Compare
Signed-off-by: Anton.Yalyshev <[email protected]>
Signed-off-by: Anton.Yalyshev <[email protected]>
This PR adds the first tabbed Java/Kotlin code examples to the documentation, allowing users to switch between languages.
I hereby agree to the terms of the JUnit Contributor License Agreement.
Definition of Done
Method preconditions are checked and documented— N/A (no new API)Public API has Javadoc and @API annotations— N/A (documentation only)Release Notes— N/A (documentation enhancement, no functional changes)