-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unit tests for write-filters task & fix a bug with generating the…
… filters file for instrumentation tests
- Loading branch information
1 parent
5fedf9a
commit 22371b2
Showing
5 changed files
with
126 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
...test/kotlin/de/mannodermaus/gradle/plugins/junit5/tasks/AndroidJUnit5WriteFiltersTests.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package de.mannodermaus.gradle.plugins.junit5.tasks | ||
|
||
import com.google.common.truth.Truth.assertThat | ||
import de.mannodermaus.gradle.plugins.junit5.internal.config.INSTRUMENTATION_FILTER_RES_FILE_NAME | ||
import de.mannodermaus.gradle.plugins.junit5.plugin.TestProjectProviderExtension | ||
import de.mannodermaus.gradle.plugins.junit5.util.assertAll | ||
import de.mannodermaus.gradle.plugins.junit5.util.evaluate | ||
import org.gradle.api.Project | ||
import org.junit.jupiter.api.BeforeEach | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.extension.RegisterExtension | ||
import java.io.File | ||
import java.nio.file.Paths | ||
import kotlin.io.path.readLines | ||
|
||
class AndroidJUnit5WriteFiltersTests { | ||
@RegisterExtension | ||
@JvmField | ||
val projectExtension = TestProjectProviderExtension() | ||
|
||
private lateinit var project: Project | ||
|
||
@BeforeEach | ||
fun beforeEach() { | ||
project = projectExtension.newProject() | ||
.asAndroidApplication() | ||
.applyJUnit5Plugin(true) { junitPlatform -> | ||
junitPlatform.filters().includeTags("included") | ||
junitPlatform.filters().excludeTags("excluded", "another-group") | ||
} | ||
.build() | ||
project.evaluate() | ||
} | ||
|
||
@Test | ||
fun `generates file structure correctly`() { | ||
// Expect a 'raw' folder inside the output, then the actual filters file in that sub-folder | ||
val output = project.runTaskAndGetOutputFolder() | ||
|
||
File(output, "raw").apply { | ||
assertAll( | ||
"output contains 'raw' folder", | ||
{ assertThat(exists()).isTrue() }, | ||
{ assertThat(isDirectory).isTrue() }, | ||
) | ||
|
||
File(this, INSTRUMENTATION_FILTER_RES_FILE_NAME).apply { | ||
assertAll( | ||
"'raw' folder contains filters file'", | ||
{ assertThat(exists()).isTrue() }, | ||
{ assertThat(isFile).isTrue() }, | ||
) | ||
} | ||
} | ||
} | ||
|
||
@Test | ||
fun `file contains expected content`() { | ||
val output = project.runTaskAndGetOutputFolder() | ||
val file = Paths.get(output.absolutePath, "raw", INSTRUMENTATION_FILTER_RES_FILE_NAME) | ||
|
||
val content = file.readLines() | ||
assertThat(content).containsExactly( | ||
"-t included", | ||
"-T excluded", | ||
"-T another-group", | ||
) | ||
} | ||
|
||
/* Private */ | ||
|
||
private fun Project.runTaskAndGetOutputFolder(): File { | ||
val task = project.tasks.getByName("writeFiltersDebugAndroidTest") as AndroidJUnit5WriteFilters | ||
task.execute() | ||
return requireNotNull(task.outputFolder) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters