Skip to content

Commit

Permalink
Merge pull request #62 from Malinskiy/fix/ignored-event-duplication
Browse files Browse the repository at this point in the history
fix(am): fix duplicated test start event in case of ignored test
  • Loading branch information
Malinskiy authored Oct 25, 2021
2 parents 6d44b8b + 8405c6c commit dd0d24a
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,6 @@ class InstrumentationResponseTransformer : ProgressiveResponseTransformer<List<T
val testName = parameters["test"]
if (className != null && testName != null) {
val id = TestIdentifier(className, testName)
events.add(TestStarted(id))
events.add(TestIgnored(id))
events.add(TestEnded(id, testMetrics))
testMetrics = linkedMapOf()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class InstrumentationResponseTransformerTest {
transformer.transform()?.let { events.addAll(it) }

assertThat(events.map { it.toString() }.reduce { acc, s -> acc + "\n" + s })
.isEqualTo(javaClass.getResourceAsStream("/instrumentation/log_3.expected").reader().readText())
.isEqualTo(javaClass.getResourceAsStream("/instrumentation/log_3.expected").reader().readText().trimEnd())
}
}

Expand All @@ -66,7 +66,7 @@ class InstrumentationResponseTransformerTest {
transformer.transform()?.let { events.addAll(it) }

assertThat(events.map { it.toString() }.reduce { acc, s -> acc + "\n" + s })
.isEqualTo(javaClass.getResourceAsStream("/instrumentation/log_2.expected").reader().readText())
.isEqualTo(javaClass.getResourceAsStream("/instrumentation/log_2.expected").reader().readText().trimEnd())
}
}

Expand All @@ -87,7 +87,7 @@ class InstrumentationResponseTransformerTest {
transformer.transform()?.let { events.addAll(it) }

assertThat(events.map { it.toString() }.reduce { acc, s -> acc + "\n" + s })
.isEqualTo(javaClass.getResourceAsStream("/instrumentation/log_1.expected").reader().readText())
.isEqualTo(javaClass.getResourceAsStream("/instrumentation/log_1.expected").reader().readText().trimEnd())
}
}

Expand Down Expand Up @@ -138,7 +138,7 @@ class InstrumentationResponseTransformerTest {
transformer.transform()?.let { events.addAll(it) }

assertThat(events.map { it.toString() }.reduce { acc, s -> acc + "\n" + s })
.isEqualTo(javaClass.getResourceAsStream("/instrumentation/log_5.expected").reader().readText())
.isEqualTo(javaClass.getResourceAsStream("/instrumentation/log_5.expected").reader().readText().trimEnd())
}
}

Expand All @@ -161,7 +161,7 @@ class InstrumentationResponseTransformerTest {
transformer.transform()?.let { events.addAll(it) }

assertThat(events.map { it.toString() }.reduce { acc, s -> acc + "\n" + s })
.isEqualTo(javaClass.getResourceAsStream("/instrumentation/log_6.expected").reader().readText().trimEnd())
.isEqualTo(javaClass.getResourceAsStream("/instrumentation/log_6.expected").reader().readText().trimEnd().trimEnd())
}

@Test
Expand All @@ -186,7 +186,7 @@ class InstrumentationResponseTransformerTest {
transformer.transform()?.let { events.addAll(it) }

assertThat(events.map { it.toString() }.reduce { acc, s -> acc + "\n" + s })
.isEqualTo(javaClass.getResourceAsStream("/instrumentation/log_6.expected").reader().readText().trimEnd())
.isEqualTo(javaClass.getResourceAsStream("/instrumentation/log_6.expected").reader().readText().trimEnd().trimEnd())
}

/**
Expand All @@ -208,7 +208,7 @@ class InstrumentationResponseTransformerTest {
transformer.transform()?.let { events.addAll(it) }

assertThat(events.map { it.toString() }.reduce { acc, s -> acc + "\n" + s })
.isEqualTo(javaClass.getResourceAsStream("/instrumentation/log_3.expected").reader().readText())
.isEqualTo(javaClass.getResourceAsStream("/instrumentation/log_3.expected").reader().readText().trimEnd())
}

@Test
Expand Down Expand Up @@ -290,4 +290,20 @@ class InstrumentationResponseTransformerTest {
assertThat(events.map { it.toString() }.reduce { acc, s -> acc + "\n" + s })
.isEqualTo(javaClass.getResourceAsStream("/instrumentation/log_11.expected").reader().readText().trimEnd())
}

@Test
fun testSingleIgnoredTest() = runBlocking {
val transformer = InstrumentationResponseTransformer()
val lines = javaClass.getResourceAsStream("/instrumentation/log_12.input").reader().readText()

val events = mutableListOf<TestEvent>()
val bytes = (lines).toByteArray(Const.DEFAULT_TRANSPORT_ENCODING)
transformer.process(bytes, 0, bytes.size)?.let {
events.addAll(it)
}
transformer.transform()?.let { events.addAll(it) }

assertThat(events.map { it.toString() }.reduce { acc, s -> acc + "\n" + s })
.isEqualTo(javaClass.getResourceAsStream("/instrumentation/log_12.expected").reader().readText().trimEnd())
}
}
4 changes: 1 addition & 3 deletions adam/src/test/resources/instrumentation/log_1.expected
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,9 @@ TestFailed(id=TestIdentifier(className=com.example.AbstractFailingTest, testName
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1932))
TestEnded(id=TestIdentifier(className=com.example.AbstractFailingTest, testName=testAlwaysFailing), metrics={})
TestStarted(id=TestIdentifier(className=com.example.ClassIgnoredTest, testName=null))
TestStarted(id=TestIdentifier(className=com.example.ClassIgnoredTest, testName=null))
TestIgnored(id=TestIdentifier(className=com.example.ClassIgnoredTest, testName=null))
TestEnded(id=TestIdentifier(className=com.example.ClassIgnoredTest, testName=null), metrics={})
TestStarted(id=TestIdentifier(className=com.example.FailedAssumptionTest, testName=ignoreTest))
TestStarted(id=TestIdentifier(className=com.example.FailedAssumptionTest, testName=ignoreTest))
TestIgnored(id=TestIdentifier(className=com.example.FailedAssumptionTest, testName=ignoreTest))
TestEnded(id=TestIdentifier(className=com.example.FailedAssumptionTest, testName=ignoreTest), metrics={})
TestStarted(id=TestIdentifier(className=com.example.FailedAssumptionTest, testName=failedAssumptionTest))
Expand Down Expand Up @@ -378,4 +376,4 @@ TestFailed(id=TestIdentifier(className=com.example.TestWithWrongName, testName=t
at android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:375)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1932))
TestEnded(id=TestIdentifier(className=com.example.TestWithWrongName, testName=testAlwaysFailing), metrics={})
TestRunEnded(elapsedTimeMillis=0, metrics={})
TestRunEnded(elapsedTimeMillis=0, metrics={})
5 changes: 5 additions & 0 deletions adam/src/test/resources/instrumentation/log_12.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
TestRunStartedEvent(testCount=1)
TestStarted(id=TestIdentifier(className=com.example.ClassIgnoredTest, testName=null))
TestIgnored(id=TestIdentifier(className=com.example.ClassIgnoredTest, testName=null))
TestEnded(id=TestIdentifier(className=com.example.ClassIgnoredTest, testName=null), metrics={})
TestRunEnded(elapsedTimeMillis=1, metrics={})
25 changes: 25 additions & 0 deletions adam/src/test/resources/instrumentation/log_12.input
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
INSTRUMENTATION_STATUS: class=com.example.ClassIgnoredTest
INSTRUMENTATION_STATUS: current=1
INSTRUMENTATION_STATUS: id=AndroidJUnitRunner
INSTRUMENTATION_STATUS: numtests=1
INSTRUMENTATION_STATUS: stream=
com.example.ClassIgnoredTest:
INSTRUMENTATION_STATUS: test=null
INSTRUMENTATION_STATUS_CODE: 1
INSTRUMENTATION_STATUS: class=com.example.ClassIgnoredTest
INSTRUMENTATION_STATUS: current=1
INSTRUMENTATION_STATUS: id=AndroidJUnitRunner
INSTRUMENTATION_STATUS: numtests=1
INSTRUMENTATION_STATUS: stream=
com.example.ClassIgnoredTest:
INSTRUMENTATION_STATUS: test=null
INSTRUMENTATION_STATUS_CODE: -3
INSTRUMENTATION_RESULT: stream=

Time: 0.001

OK (0 tests)


Error: Failed to generate Emma/JaCoCo coverage.
INSTRUMENTATION_CODE: -1

0 comments on commit dd0d24a

Please sign in to comment.