Slackbot
07/19/2023, 12:22 PMTom Koptel
07/19/2023, 12:29 PMtest/
source set under the module where you are hosting the convention plugin.
In the test you need recreate Android project structure in some temporary dir. Here is an example from gradle-play-publisher.Julio Cesar Bueno Cotta
07/19/2023, 12:30 PMBen Stav
07/19/2023, 12:37 PMbuildSrc
showed how to test a plugin, I sort of recall seeing a unit test class simulating adding a project folder and seeing spotless fail, I'll try to dig it upBen Stav
07/19/2023, 12:41 PMbuildSrc/src/test/kotlin/com/example/
It references TestKit, which might also be a good readJulio Cesar Bueno Cotta
07/19/2023, 12:44 PMprojectDir
in my tests and assert in the results of a task like "assembleDebug"Tom Koptel
07/19/2023, 12:50 PMGradleRunner
. In the sample shared by Ben you can find the PluginTest
class that creates files for the project and the exposes runTask
program.
So in you case you need to create
settings.gradle
build.gradle
src/main/AndroidManifest.xml
local.properties
It is important to have path to SDK in local.properties
// root is a tmp folder generated for test
root.resolve("local.properties").writeText("""sdk.dir=${System.getenv()["ANDROID_HOME"]}""")
if not set you won’t be able to call assembleDebug
.Julio Cesar Bueno Cotta
07/19/2023, 12:53 PMBen Stav
07/19/2023, 1:12 PMtargetSdk
, or checking that Proguard is enabled, etc.Julio Cesar Bueno Cotta
07/19/2023, 1:21 PMTom Koptel
07/19/2023, 1:39 PMProject
apply plugin and then with the help of android
extension access the property your are modifying to assert that the specific variant has API set and minify enabled.
Here is an example of how to create Project
instance and then apply plugin to it directly.
https://github.com/KeepSafe/dexcount-gradle-plugin/blob/362bcf369aabc2c937491488f4[…]st/groovy/com/getkeepsafe/dexcount/DexCountExtensionSpec.groovy