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

[RunAllTests] Consolidate testing to ensure all tests are covered in Bazel CI #2697

Merged
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
473 changes: 28 additions & 445 deletions app/BUILD.bazel

Large diffs are not rendered by default.

35 changes: 20 additions & 15 deletions app/app_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,32 @@
Macros for app module tests.
"""

load("//:oppia_android_test.bzl", "oppia_android_test")
load("//:oppia_android_test.bzl", "oppia_android_module_level_test")

# TODO(#1620): Remove module-specific test macros once Gradle is removed
def app_test(name, srcs, test_class, deps, **kwargs):
# Creates individual tests for test files in the app module.
#
# Args:
# name: str. The name of the Kotlin test file without the '.kt' suffix.
# src: list of str. The list of test files to be run.
# test_class: str. The package of the src file. Example: If the src is 'FakeEventLoggerTest.kt',
# then the test_class would be "org.oppia.testing.FakeEventLoggerTest".
# deps: list of str. The list of dependencies needed to build and run this test.
# kwargs: additional parameters to pass to oppia_android_test.
def app_test(name, processed_src, test_path_prefix, filtered_tests, deps, **kwargs):
"""
Creates individual tests for test files in the app module.

oppia_android_test(
Args:
name: str. The relative path to the Kotlin test file.
processed_src: str. The source to a processed version of the test that should be used
instead of the original.
test_path_prefix: str. The prefix of the test path (which is used to extract the qualified
class name of the test suite).
filtered_tests: list of str. The test files that should not have tests defined for them.
deps: list of str. The list of dependencies needed to build and run this test.
**kwargs: additional parameters passed in.
"""
oppia_android_module_level_test(
name = name,
srcs = srcs + ["src/test/java/DataBinderMapperImpl.java"],
processed_src = processed_src,
filtered_tests = filtered_tests,
test_path_prefix = test_path_prefix,
deps = deps,
custom_package = "org.oppia.android.app.test",
test_class = test_class,
test_manifest = "src/test/AndroidManifest.xml",
deps = deps,
additional_srcs = ["src/test/java/DataBinderMapperImpl.java"],
enable_data_binding = True,
**kwargs
)
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ import org.robolectric.annotation.LooperMode
import javax.inject.Inject
import javax.inject.Singleton

private const val KEY_READING_TEXT_SIZE_PREFERENCE_TITLE = "READING_TEXT_SIZE_PREFERENCE"
private const val APP_LANGUAGE_PREFERENCE_TITLE_EXTRA_KEY =
"AppLanguageActivity.app_language_preference_title"
private const val KEY_AUDIO_LANGUAGE_PREFERENCE_TITLE = "AUDIO_LANGUAGE_PREFERENCE"

@RunWith(AndroidJUnit4::class)
@Config(application = OptionsFragmentTest.TestApplication::class)
class OptionsFragmentTest {
Expand Down Expand Up @@ -112,12 +117,7 @@ class OptionsFragmentTest {
click()
)
intended(hasComponent(ReadingTextSizeActivity::class.java.name))
intended(
hasExtra(
ReadingTextSizeActivity.KEY_READING_TEXT_SIZE_PREFERENCE_TITLE,
READING_TEXT_SIZE
)
)
intended(hasExtra(KEY_READING_TEXT_SIZE_PREFERENCE_TITLE, READING_TEXT_SIZE))
}
}

Expand All @@ -135,12 +135,7 @@ class OptionsFragmentTest {
click()
)
intended(hasComponent(AppLanguageActivity::class.java.name))
intended(
hasExtra(
AppLanguageActivity.APP_LANGUAGE_PREFERENCE_TITLE_EXTRA_KEY,
APP_LANGUAGE
)
)
intended(hasExtra(APP_LANGUAGE_PREFERENCE_TITLE_EXTRA_KEY, APP_LANGUAGE))
}
}

Expand All @@ -158,12 +153,7 @@ class OptionsFragmentTest {
click()
)
intended(hasComponent(AudioLanguageActivity::class.java.name))
intended(
hasExtra(
AudioLanguageActivity.KEY_AUDIO_LANGUAGE_PREFERENCE_TITLE,
AUDIO_LANGUAGE
)
)
intended(hasExtra(KEY_AUDIO_LANGUAGE_PREFERENCE_TITLE, AUDIO_LANGUAGE))
}
}

Expand Down
11 changes: 7 additions & 4 deletions app/test_with_resources.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ Macros for app module tests that depend on resources.
"""

def test_with_resources(name):
# Genrule for test files.
# Because each databinding library must have a unique package name and manifest, resources must be
# imported using the proper package name when building with Bazel. This genrule alters those imports
# in order to keep Gradle building.
"""
Genrule for test files.

Because each databinding library must have a unique package name and manifest, resources must be
imported using the proper package name when building with Bazel. This genrule alters those
imports in order to keep Gradle building.
"""

native.genrule(
name = "update_" + name[0:-3],
Expand Down
Loading