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

Test filtering #116

Merged
merged 2 commits into from
May 9, 2023
Merged
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: 26 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,32 @@ android {
excludes = ['jdk.internal.*']
}
}
// should let the tests run with with gradle via -DincludeTags="tag1,tag2" -DexcludeTags="tag3,tag4"
// https://github.com/mannodermaus/android-junit5/wiki/Configuration
// https://junit.org/junit5/docs/current/user-guide/#writing-tests-tagging-and-filtering
// https://www.vogella.com/tutorials/AndroidTesting/article.html
junitPlatform {
String includedTagsProperty = System.getProperty("includeTags")
boolean includedTagsPropertySet = includedTagsProperty != null

String excludedTagsProperty = System.getProperty("excludeTags")
boolean excludedTagsPropertySet = excludedTagsProperty != null

if (includedTagsPropertySet && excludedTagsPropertySet) {
filters("debug") {
includeTags includedTagsProperty
excludeTags excludedTagsProperty
}
} else if (includedTagsPropertySet && !excludedTagsPropertySet) {
filters("debug") {
includeTags includedTagsProperty
}
} else if (!includedTagsPropertySet && excludedTagsPropertySet) {
filters("debug") {
excludeTags excludedTagsProperty
}
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ package com.example.myapplication
import androidx.test.platform.app.InstrumentationRegistry
import de.mannodermaus.junit5.ActivityScenarioExtension
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Tag
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.Timeout
import org.junit.jupiter.api.extension.RegisterExtension
import org.slf4j.LoggerFactory

/**
* Instrumented test, which will execute on an Android device.
Expand All @@ -14,13 +16,16 @@ import org.junit.jupiter.api.extension.RegisterExtension
*/
@Timeout(30)
class ExampleInstrumentedTest {
private val logger = LoggerFactory.getLogger(javaClass)

@JvmField
@RegisterExtension
var scenarioExtension = ActivityScenarioExtension.launch(
MainActivity::class.java
)

@Test
@Tag("OTHERTEST")
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
Expand All @@ -29,4 +34,10 @@ class ExampleInstrumentedTest {
val scenario = scenarioExtension.scenario
scenario.onActivity { }
}

@Test
@Tag("TAGTEST")
fun test2() {
logger.debug("test2")
}
}