Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove testing flags #66

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 12 additions & 14 deletions src/main/kotlin/com/jaredsburrows/spoon/SpoonTask.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import com.android.ddmlib.testrunner.IRemoteAndroidTestRunner.TestSize
import com.squareup.spoon.SpoonRunner
import org.gradle.api.DefaultTask
import org.gradle.api.GradleException
import org.gradle.api.Task
import org.gradle.api.tasks.TaskAction
import java.io.File
import java.time.Duration
import org.gradle.api.Task

/** A [Task] that creates and runs the Spoon test runner. */
open class SpoonTask : DefaultTask() { // tasks can't be final
Expand All @@ -17,26 +17,21 @@ open class SpoonTask : DefaultTask() { // tasks can't be final
}

/** Use our Spoon extension. */
lateinit var extension: SpoonExtension

var extension: SpoonExtension = SpoonExtension()
/** Application APK (eg. app-debug.apk). */
lateinit var applicationApk: File

var applicationApk: File? = null
/** Instrumentation APK (eg. app-debug-androidTest.apk). */
lateinit var instrumentationApk: File

var instrumentationApk: File? = null
/** Results baseOutputDir. */
lateinit var outputDir: File
var outputDir: File? = null

/** TESTING ONLY */
var testing: Boolean = false
var testValue: Boolean = true
var spoonRenderer: SpoonRunner.Builder? = null

@Suppress("unused")
@TaskAction
fun spoonTask() {
if (extension.className.isEmpty() && extension.methodName.isNotEmpty()) {
if (extension.className.isEmpty() and extension.methodName.isNotEmpty()) {
throw IllegalStateException("'${extension.methodName}' must have a fully qualified class " +
"name.")
}
Expand All @@ -59,8 +54,10 @@ open class SpoonTask : DefaultTask() { // tasks can't be final
.setClearAppDataBeforeEachTest(extension.clearAppDataBeforeEachTest)

// APKs
if (!testing) {
instrumentationApk?.let {
builder.setTestApk(instrumentationApk)
}
applicationApk?.let {
builder.addOtherApk(applicationApk)
}

Expand Down Expand Up @@ -116,8 +113,9 @@ open class SpoonTask : DefaultTask() { // tasks can't be final

spoonRenderer = builder

val success = if (testing) testValue else builder.build().run()
if (!success && !extension.ignoreFailures) {
builder.build().run()

if (!extension.ignoreFailures) {
throw GradleException("Tests failed! " +
"See ${ConsoleRenderer.asClickableFileUrl(File(outputDir, "index.html"))}")
}
Expand Down
5 changes: 0 additions & 5 deletions src/test/groovy/com/jaredsburrows/spoon/SpoonTaskSpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ final class SpoonTaskSpec extends Specification {
project.evaluate()

SpoonTask task = project.tasks.getByName(taskName) as SpoonTask
task.testing = true
task.applicationApk = appApk
task.instrumentationApk = testApk
task.execute()
Expand Down Expand Up @@ -146,7 +145,6 @@ final class SpoonTaskSpec extends Specification {
project.evaluate()

SpoonTask task = project.tasks.getByName(taskName) as SpoonTask
task.testing = true
task.applicationApk = appApk
task.instrumentationApk = testApk
task.execute()
Expand Down Expand Up @@ -248,7 +246,6 @@ final class SpoonTaskSpec extends Specification {
project.evaluate()

SpoonTask task = project.tasks.getByName(taskName) as SpoonTask
task.testing = true
task.applicationApk = testApk
task.instrumentationApk = testApk
task.execute()
Expand Down Expand Up @@ -348,8 +345,6 @@ final class SpoonTaskSpec extends Specification {
project.evaluate()

SpoonTask task = project.tasks.getByName(taskName) as SpoonTask
task.testing = true
task.testValue = false
task.applicationApk = appApk
task.instrumentationApk = testApk
task.execute()
Expand Down