Skip to content
This repository was archived by the owner on Dec 7, 2019. It is now read-only.

Commit c095a4a

Browse files
authored
Updated handling of crashed application during test run. (#130)
1 parent 3f9f650 commit c095a4a

File tree

3 files changed

+37
-3
lines changed

3 files changed

+37
-3
lines changed

composer/src/main/kotlin/com/gojuno/composer/Instrumentation.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.gojuno.composer
22

3-
import com.gojuno.composer.InstrumentationTest.Status.*
3+
import com.gojuno.composer.InstrumentationTest.Status.Failed
4+
import com.gojuno.composer.InstrumentationTest.Status.Ignored
5+
import com.gojuno.composer.InstrumentationTest.Status.Passed
46
import rx.Observable
57
import java.io.File
68

@@ -61,7 +63,7 @@ private fun String.parseInstrumentationStatusValue(key: String): String = this
6163
.trim()
6264

6365
private fun String.throwIfError(output: File) = when {
64-
contains("INSTRUMENTATION_RESULT: shortMsg=Process crashed") -> {
66+
contains("INSTRUMENTATION_RESULT: shortMsg=") -> {
6567
throw Exception("Application process crashed. Check Logcat output for more details.")
6668
}
6769

composer/src/test/kotlin/com/gojuno/composer/InstrumentationSpec.kt

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.gojuno.composer
22

3-
import com.gojuno.composer.InstrumentationTest.Status.*
3+
import com.gojuno.composer.InstrumentationTest.Status.Failed
4+
import com.gojuno.composer.InstrumentationTest.Status.Ignored
5+
import com.gojuno.composer.InstrumentationTest.Status.Passed
46
import org.assertj.core.api.Assertions.assertThat
57
import org.jetbrains.spek.api.Spek
68
import org.jetbrains.spek.api.dsl.context
@@ -736,4 +738,22 @@ at android.app.Instrumentation${'$'}InstrumentationThread.run(Instrumentation.ja
736738
)
737739
}
738740
}
741+
742+
context("read output with crash") {
743+
744+
val outputFile = fileFromJarResources<InstrumentationSpec>("instrumentation-output-app-crash.txt")
745+
val entries by memoized { readInstrumentationOutput(outputFile) }
746+
val entriesSubscriber by memoized { TestSubscriber<InstrumentationEntry>() }
747+
748+
perform {
749+
entries.subscribe(entriesSubscriber)
750+
entriesSubscriber.awaitTerminalEvent(30, SECONDS)
751+
}
752+
753+
it("emits exception describing issue") {
754+
assertThat(entriesSubscriber.onErrorEvents.first()).hasMessage(
755+
"Application process crashed. Check Logcat output for more details."
756+
)
757+
}
758+
}
739759
})
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
INSTRUMENTATION_STATUS: numtests=1
2+
INSTRUMENTATION_STATUS: stream=
3+
com.example.test.TestClass:
4+
INSTRUMENTATION_STATUS: id=AndroidJUnitRunner
5+
INSTRUMENTATION_STATUS: test=crashTest
6+
INSTRUMENTATION_STATUS: class=com.example.test.TestClass:
7+
INSTRUMENTATION_STATUS: current=1
8+
INSTRUMENTATION_STATUS_CODE: 1
9+
INSTRUMENTATION_RESULT: shortMsg=java.lang.NullPointerException
10+
INSTRUMENTATION_RESULT: longMsg=java.lang.NullPointerException: Attempt to invoke virtual method 'void java.util.logging.Logger.log(java.util.logging.Level, java.lang.String, java.lang.Throwable)' on a null object reference
11+
12+
INSTRUMENTATION_CODE: 0

0 commit comments

Comments
 (0)