Michael Vandendriessche
01/19/2022, 2:09 PMtestImplementation 'io.kotest:kotest-runner-junit5-jvm:5.1.0'
testImplementation 'io.kotest:kotest-assertions-core-jvm:5.1.0'
Currently my test dependencies look like this (yes with all the comments... don't worry, I didn't commit it yet)
// testImplementation 'junit:junit:4.12'
testImplementation 'io.kotest:kotest-runner-junit5-jvm:5.1.0'
testImplementation 'io.kotest:kotest-assertions-core-jvm:5.1.0'
// testImplementation 'io.kotest:kotest-assertions-json-jvm:5.1.0'
testImplementation 'io.kotest.extensions:kotest-extensions-robolectric:0.5.0'
implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version" // M: Why do I need this? ask in the kotlin kotest channel
// testImplementation 'org.json:json:20180813' // M: needed for using JSONObject in unit tests, which is part of the android framework
// testImplementation 'com.googlecode.json-simple:json-simple:1.1.1' // M: needed for using JSONObject in unit tests, which is part of the android framework
// testImplementation 'org.robolectric:robolectric:4.6' // M: use kotest robolectric instead
// testImplementation "de.mannodermaus.gradle.plugins:android-junit5:1.8.2.0"
// (Required) Writing and executing Unit Tests on the JUnit Platform
// testImplementation "org.junit.jupiter:junit-jupiter-api:5.8.2"
// testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:5.8.2"
// (Optional) If you need "Parameterized Tests"
// testImplementation "org.junit.jupiter:junit-jupiter-params:5.8.2"
// androidTestImplementation 'com.android.support.test:rules:1.0.2'
// androidTestImplementation 'com.android.support.test:runner:1.0.2'
// androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
I'm using robolectric here because I wanted to test something with json but apparently that's part of the android platform and couldn't get it to work by including json dependencies separately.
I had to include the kotlin-reflect library, however I'm not doing any reflection. Why do I need this dependency? Where is it using reflection?
At this moment I'm having following error about androidx.
This project uses AndroidX dependencies, but the 'android.useAndroidX' property is not enabled. Set this property to true in the gradle.properties file and retry.
The following AndroidX dependencies are detected: androidx.test:monitor:1.4.0, androidx.annotation:annotation:1.1.0
Where is androidx used? Why do I need to add this? I do not see any references to androidx in our codebase. I suppose I will add it but I want to understand it.
I was wondering if I also should include the mannodermaus plugin for junit5 and the junit dependencies or those are covered by kotest already or are those not relevant for kotest?
Most of my android knowledge dates from around 2015. If someone can shed more light on the things above, that would be great!
I'm happy to be working on Android again! šEmil Kantis
01/19/2022, 2:21 PMMichael Vandendriessche
01/19/2022, 2:22 PMJSONObject
Emil Kantis
01/19/2022, 2:22 PMMichael Vandendriessche
01/19/2022, 2:23 PMdescribe("createFromJSON") {
describe("with a valid json parameter"){
val json = JSONObject(filterValidJson) //M: JSONObject is part of Android. unit test fails here.
val createdFilter = Filter.createFromJSON(json)
it("should create a filter with the same values"){
assertSoftly(createdFilter){
id shouldBe 1
name shouldBe "filtername"
minimum shouldBe 1
maximum shouldBe 3
displayOrder shouldBe 10
}
}
}
This is the only test I have right now (except a true is true test which worked before I made more changes)Michael Vandendriessche
01/19/2022, 2:23 PM@JvmStatic
@Throws(JSONException::class)
fun createFromJSON(json: JSONObject): Filter {
return Filter(
id = json.getInt(KEY_ID),
name = json.getString(KEY_NAME),
minimum = json.getInt(KEY_MINIMUM),
maximum = json.getInt(KEY_MAXIMUM),
displayOrder = json.getInt(KEY_DISPLAY_ORDER)
)
}
Michael Vandendriessche
01/19/2022, 2:24 PMMichael Vandendriessche
01/19/2022, 2:31 PMjava.lang.RuntimeException: Stub!
at org.json.JSONObject.<init>(JSONObject.java:120)
After I added android.useAndroidX=true
to the gradle propertiesEmil Kantis
01/19/2022, 2:40 PMMichael Vandendriessche
01/19/2022, 2:42 PM