-
Notifications
You must be signed in to change notification settings - Fork 434
sample shows how you can test your custom buildSrc logic with a JUnit4 test #1302
Conversation
…ogic in buildSrc using JUnit4 Unit tests. Signed-off-by: Alphonse Bendt <[email protected]>
==================== | ||
|
||
Sample project setup to show how you can test your _buildSrc_ custom build logic using | ||
Junit4 Unit tests. |
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.
Junit5 is already released.
I would recommend to use an exmaple with Junit5...
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.
we still use JUnit4, this is why the sample is based on it.
I'd be happy to provide more samples e.g. using JUnit5 or Spek if there's interest.
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.
@StefMa
is it acceptable for you to keep the junit4 example or would you prefer to have a junit5 one?
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 am not a maintainer of this Repo nor I work at gradle 🙃. I, personally, would show an example with junit 5 because it's the latest version. There is literally no need to stick at junit 4.
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.
Ok thanks.
I have created a new PR (#1317) and will close this one.
Sample project setup to show how you can test your _buildSrc_ custom build logic using | ||
Junit4 Unit tests. | ||
|
||
`./gradlew hello` this task uses a build helper function from _buildSrc_. The code inside _buildSrc_ will be compiled and tested prior to the execution of this task. |
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.
Link the buildSrc
in that markdown file: [buildSrc](buildSrc/)
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.
done
@@ -0,0 +1,12 @@ | |||
import tools.sayHelloTo | |||
|
|||
tasks { |
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.
For a single task the TaskScope
is a little bit out of bounds.
I would recommend to use either val hello by tasks.creating {}
or directly tasks.register("hello") {}
..
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.
done
} | ||
|
||
dependencies { | ||
testCompile("junit:junit:4.12") |
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.
compile
is deprecated. Use implementation
@@ -0,0 +1,3 @@ | |||
package tools | |||
|
|||
fun sayHelloTo(name: String) = "Hello $name" |
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.
The class of that name (and package) is a little bit missleading when here is just an "sayHello" function inside.
Renaming the package to greeting
and the filename to Greeter.kt
.
As I remember correctly Gradle use these convention in mutliple other samples too..
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.
done
Signed-off-by: Alphonse Bendt <[email protected]>
Context
While learning how to use the Kotlin DSL for Gradle I found the samples to be immensely helpful. However I missed a sample that demonstrated how to unit-test your custom logic in buildSrc with. I think other users also could benefit from some this sample.
#1087
Contributor Checklist
develop
branch./gradlew check --parallel