diff --git a/app/BUILD.bazel b/app/BUILD.bazel index 0ca6960ecbf..cfe50771953 100644 --- a/app/BUILD.bazel +++ b/app/BUILD.bazel @@ -699,121 +699,20 @@ TEST_DEPS = [ "//utility", ] -# App module tests. - -# Note that if a test file imports resources or binding files, it must be wrapped by +# App module tests. Note that all tests are assumed to be tests with resources (even though not all +# are). Note that if a test file imports resources or binding files, it must be wrapped by # test_with_resources(). -app_test( - name = "HomeActivityLocalTest", - srcs = ["src/test/java/org/oppia/android/app/home/HomeActivityLocalTest.kt"], - test_class = "org.oppia.android.app.home.HomeActivityLocalTest", - deps = TEST_DEPS, -) - -app_test( - name = "ExplorationActivityLocalTest", - srcs = ["src/test/java/org/oppia/android/app/player/exploration/ExplorationActivityLocalTest.kt"], - test_class = "org.oppia.android.app.player.exploration.ExplorationActivityLocalTest", - deps = TEST_DEPS, -) - -app_test( - name = "StateFragmentLocalTest", - srcs = [test_with_resources("src/test/java/org/oppia/android/app/player/state/StateFragmentLocalTest.kt")], - test_class = "org.oppia.android.app.player.state.StateFragmentLocalTest", - deps = TEST_DEPS, -) - -app_test( - name = "ProfileChooserFragmentLocalTest", - srcs = ["src/test/java/org/oppia/android/app/profile/ProfileChooserFragmentLocalTest.kt"], - test_class = "org.oppia.android.app.profile.ProfileChooserFragmentLocalTest", - deps = TEST_DEPS, -) - -app_test( - name = "StoryActivityLocalTest", - srcs = ["src/test/java/org/oppia/android/app/story/StoryActivityLocalTest.kt"], - test_class = "org.oppia.android.app.story.StoryActivityLocalTest", - deps = TEST_DEPS, -) - -app_test( - name = "CompletedStoryListSpanTest", - srcs = [test_with_resources("src/test/java/org/oppia/android/app/testing/CompletedStoryListSpanTest.kt")], - test_class = "org.oppia.android.app.testing.CompletedStoryListSpanTest", - deps = TEST_DEPS, -) - -app_test( - name = "OngoingTopicListSpanTest", - srcs = [test_with_resources("src/test/java/org/oppia/android/app/testing/OngoingTopicListSpanTest.kt")], - test_class = "org.oppia.android.app.testing.OngoingTopicListSpanTest", - deps = TEST_DEPS, -) - -app_test( - name = "ProfileChooserSpanTest", - srcs = ["src/test/java/org/oppia/android/app/testing/ProfileChooserSpanTest.kt"], - test_class = "org.oppia.android.app.testing.ProfileChooserSpanTest", - deps = TEST_DEPS, -) - -app_test( - name = "TopicRevisionSpanTest", - srcs = [test_with_resources("src/test/java/org/oppia/android/app/testing/TopicRevisionSpanTest.kt")], - test_class = "org.oppia.android.app.testing.TopicRevisionSpanTest", - deps = TEST_DEPS, -) - -app_test( - name = "PlayerSplitScreenTesting", - srcs = ["src/test/java/org/oppia/android/app/testing/player/split/PlayerSplitScreenTesting.kt"], - test_class = "org.oppia.android.app.testing.player.split.PlayerSplitScreenTesting", - deps = TEST_DEPS, -) - -app_test( - name = "StateFragmentAccessibilityTest", - srcs = [test_with_resources("src/test/java/org/oppia/android/app/testing/player/state/StateFragmentAccessibilityTest.kt")], - test_class = "org.oppia.android.app.testing.player.state.StateFragmentAccessibilityTest", - deps = TEST_DEPS, -) - -app_test( - name = "TopicInfoFragmentLocalTest", - srcs = ["src/test/java/org/oppia/android/app/topic/info/TopicInfoFragmentLocalTest.kt"], - test_class = "org.oppia.android.app.topic.info.TopicInfoFragmentLocalTest", - deps = TEST_DEPS, -) - -app_test( - name = "TopicLessonsFragmentLocalTest", - srcs = ["src/test/java/org/oppia/android/app/topic/lessons/TopicLessonsFragmentLocalTest.kt"], - test_class = "org.oppia.android.app.topic.lessons.TopicLessonsFragmentLocalTest", - deps = TEST_DEPS, -) - -app_test( - name = "RevisionCardActivityLocalTest", - srcs = ["src/test/java/org/oppia/android/app/topic/revisioncard/RevisionCardActivityLocalTest.kt"], - test_class = "org.oppia.android.app.topic.revisioncard.RevisionCardActivityLocalTest", - deps = TEST_DEPS, -) - -# App Module Shared Tests - -app_test( - name = "AdministratorControlsActivityTest", - srcs = [test_with_resources("src/sharedTest/java/org/oppia/android/app/administratorcontrols/AdministratorControlsActivityTest.kt")], - test_class = "org.oppia.android.app.administratorcontrols.AdministratorControlsActivityTest", - deps = TEST_DEPS, -) +# Qualified file paths for test classes that have been migrated over to their own packages & +# shouldn't be defined as module-level tests. +# keep sorted +MIGRATED_TESTS = [ +] -app_test( - name = "AppVersionActivityTest", - srcs = [test_with_resources("src/sharedTest/java/org/oppia/android/app/administratorcontrols/AppVersionActivityTest.kt")], +# Unit tests. +[app_test( + name = test_file_path, + filtered_tests = MIGRATED_TESTS, manifest_values = { "applicationId": "org.oppia.android", "minSdkVersion": "19", @@ -821,342 +720,26 @@ app_test( "versionCode": "0", "versionName": "0.1-alpha", }, - test_class = "org.oppia.android.app.administratorcontrols.AppVersionActivityTest", - deps = TEST_DEPS, -) - -app_test( - name = "CompletedStoryListActivityTest", - srcs = [test_with_resources("src/sharedTest/java/org/oppia/android/app/completedstorylist/CompletedStoryListActivityTest.kt")], - test_class = "org.oppia.android.app.completedstorylist.CompletedStoryListActivityTest", + processed_src = test_with_resources(test_file_path), + test_path_prefix = "src/test/java/", deps = TEST_DEPS, -) +) for test_file_path in glob(["src/test/java/org/oppia/android/app/**/*Test.kt"])] -app_test( - name = "FAQListFragmentTest", - srcs = [test_with_resources("src/sharedTest/java/org/oppia/android/app/faq/FAQListFragmentTest.kt")], - test_class = "org.oppia.android.app.faq.FAQListFragmentTest", - deps = TEST_DEPS, -) - -app_test( - name = "FAQSingleActivityTest", - srcs = [test_with_resources("src/sharedTest/java/org/oppia/android/app/faq/FAQSingleActivityTest.kt")], - test_class = "org.oppia.android.app.faq.FAQSingleActivityTest", - deps = TEST_DEPS, -) - -app_test( - name = "HelpFragmentTest", - srcs = [test_with_resources("src/sharedTest/java/org/oppia/android/app/help/HelpFragmentTest.kt")], - test_class = "org.oppia.android.app.help.HelpFragmentTest", - deps = TEST_DEPS, -) - -app_test( - name = "HomeActivityTest", - srcs = [test_with_resources("src/sharedTest/java/org/oppia/android/app/home/HomeActivityTest.kt")], - test_class = "org.oppia.android.app.home.HomeActivityTest", - deps = TEST_DEPS, -) - -app_test( - name = "RecentlyPlayedFragmentTest", - srcs = [test_with_resources("src/sharedTest/java/org/oppia/android/app/home/RecentlyPlayedFragmentTest.kt")], - test_class = "org.oppia.android.app.home.RecentlyPlayedFragmentTest", - deps = TEST_DEPS, -) - -app_test( - name = "MyDownloadsFragmentTest", - srcs = [test_with_resources("src/sharedTest/java/org/oppia/android/app/mydownloads/MyDownloadsFragmentTest.kt")], - test_class = "org.oppia.android.app.mydownloads.MyDownloadsFragmentTest", - deps = TEST_DEPS, -) - -# TODO(#973): Fix app module tests for Robolectric. -app_test( - name = "OnboardingFragmentTest", - srcs = [test_with_resources("src/sharedTest/java/org/oppia/android/app/onboarding/OnboardingFragmentTest.kt")], - test_class = "org.oppia.android.app.onboarding.OnboardingFragmentTest", - deps = TEST_DEPS, -) - -app_test( - name = "OngoingTopicListActivityTest", - srcs = [test_with_resources("src/sharedTest/java/org/oppia/android/app/ongoingtopiclist/OngoingTopicListActivityTest.kt")], - test_class = "org.oppia.android.app.ongoingtopiclist.OngoingTopicListActivityTest", - deps = TEST_DEPS, -) - -app_test( - name = "OptionsFragmentTest", - srcs = [test_with_resources("src/sharedTest/java/org/oppia/android/app/options/OptionsFragmentTest.kt")], - test_class = "org.oppia.android.app.options.OptionsFragmentTest", - deps = TEST_DEPS, -) - -app_test( - name = "HtmlParserTest", - srcs = [test_with_resources("src/sharedTest/java/org/oppia/android/app/parser/HtmlParserTest.kt")], - test_class = "org.oppia.android.app.parser.HtmlParserTest", - deps = TEST_DEPS, -) - -app_test( - name = "AudioFragmentTest", - srcs = [test_with_resources("src/sharedTest/java/org/oppia/android/app/player/audio/AudioFragmentTest.kt")], - test_class = "org.oppia.android.app.player.audio.AudioFragmentTest", - deps = TEST_DEPS, -) - -app_test( - name = "ExplorationActivityTest", - srcs = [test_with_resources("src/sharedTest/java/org/oppia/android/app/player/exploration/ExplorationActivityTest.kt")], - test_class = "org.oppia.android.app.player.exploration.ExplorationActivityTest", - deps = TEST_DEPS, -) - -app_test( - name = "StateFragmentTest", - srcs = [test_with_resources("src/sharedTest/java/org/oppia/android/app/player/state/StateFragmentTest.kt")], - test_class = "org.oppia.android.app.player.state.StateFragmentTest", - deps = TEST_DEPS, -) - -app_test( - name = "AddProfileActivityTest", - srcs = [test_with_resources("src/sharedTest/java/org/oppia/android/app/profile/AddProfileActivityTest.kt")], - test_class = "org.oppia.android.app.profile.AddProfileActivityTest", - deps = TEST_DEPS, -) - -app_test( - name = "AdminAuthActivityTest", - srcs = [test_with_resources("src/sharedTest/java/org/oppia/android/app/profile/AdminAuthActivityTest.kt")], - test_class = "org.oppia.android.app.profile.AdminAuthActivityTest", - deps = TEST_DEPS, -) - -app_test( - name = "AdminPinActivityTest", - srcs = [test_with_resources("src/sharedTest/java/org/oppia/android/app/profile/AdminPinActivityTest.kt")], - test_class = "org.oppia.android.app.profile.AdminPinActivityTest", - deps = TEST_DEPS, -) - -app_test( - name = "PinPasswordActivityTest", - srcs = [test_with_resources("src/sharedTest/java/org/oppia/android/app/profile/PinPasswordActivityTest.kt")], - test_class = "org.oppia.android.app.profile.PinPasswordActivityTest", - deps = TEST_DEPS, -) - -# TODO(#973): Fix app module tests for Robolectric. -app_test( - name = "ProfileChooserFragmentTest", - srcs = [test_with_resources("src/sharedTest/java/org/oppia/android/app/profile/ProfileChooserFragmentTest.kt")], - test_class = "org.oppia.android.app.profile.ProfileChooserFragmentTest", - deps = TEST_DEPS, -) - -app_test( - name = "ProfilePictureActivityTest", - srcs = [test_with_resources("src/sharedTest/java/org/oppia/android/app/profileprogress/ProfilePictureActivityTest.kt")], - test_class = "org.oppia.android.app.profileprogress.ProfilePictureActivityTest", - deps = TEST_DEPS, -) - -app_test( - name = "ProfileProgressFragmentTest", - srcs = [test_with_resources("src/sharedTest/java/org/oppia/android/app/profileprogress/ProfileProgressFragmentTest.kt")], - test_class = "org.oppia.android.app.profileprogress.ProfileProgressFragmentTest", - deps = TEST_DEPS, -) - -app_test( - name = "BindableAdapterTest", - srcs = [test_with_resources("src/sharedTest/java/org/oppia/android/app/recyclerview/BindableAdapterTest.kt")], - test_class = "org.oppia.android.app.recyclerview.BindableAdapterTest", - deps = TEST_DEPS, -) - -app_test( - name = "ProfileEditActivityTest", - srcs = [test_with_resources("src/sharedTest/java/org/oppia/android/app/settings/profile/ProfileEditActivityTest.kt")], - test_class = "org.oppia.android.app.settings.profile.ProfileEditActivityTest", - deps = TEST_DEPS, -) - -app_test( - name = "ProfileListFragmentTest", - srcs = [test_with_resources("src/sharedTest/java/org/oppia/android/app/settings/profile/ProfileListFragmentTest.kt")], - test_class = "org.oppia.android.app.settings.profile.ProfileListFragmentTest", - deps = TEST_DEPS, -) - -app_test( - name = "ProfileRenameActivityTest", - srcs = [test_with_resources("src/sharedTest/java/org/oppia/android/app/settings/profile/ProfileRenameActivityTest.kt")], - test_class = "org.oppia.android.app.settings.profile.ProfileRenameActivityTest", - deps = TEST_DEPS, -) - -app_test( - name = "ProfileResetPinActivityTest", - srcs = [test_with_resources("src/sharedTest/java/org/oppia/android/app/settings/profile/ProfileResetPinActivityTest.kt")], - test_class = "org.oppia.android.app.settings.profile.ProfileResetPinActivityTest", - deps = TEST_DEPS, -) - -app_test( - name = "SplashActivityTest", - srcs = [test_with_resources("src/sharedTest/java/org/oppia/android/app/splash/SplashActivityTest.kt")], - test_class = "org.oppia.android.app.splash.SplashActivityTest", - deps = TEST_DEPS, -) - -app_test( - name = "StoryActivityTest", - srcs = [test_with_resources("src/sharedTest/java/org/oppia/android/app/story/StoryActivityTest.kt")], - test_class = "org.oppia.android.app.story.StoryActivityTest", - deps = TEST_DEPS, -) - -app_test( - name = "StoryFragmentTest", - srcs = [test_with_resources("src/sharedTest/java/org/oppia/android/app/story/StoryFragmentTest.kt")], - test_class = "org.oppia.android.app.story.StoryFragmentTest", - deps = TEST_DEPS, -) - -app_test( - name = "DragDropTestActivityTest", - srcs = [test_with_resources("src/sharedTest/java/org/oppia/android/app/testing/DragDropTestActivityTest.kt")], - test_class = "org.oppia.android.app.testing.DragDropTestActivityTest", - deps = TEST_DEPS, -) - -app_test( - name = "ImageRegionSelectionInteractionViewTest", - srcs = [test_with_resources("src/sharedTest/java/org/oppia/android/app/testing/ImageRegionSelectionInteractionViewTest.kt")], - test_class = "org.oppia.android.app.testing.ImageRegionSelectionInteractionViewTest", - deps = TEST_DEPS, -) - -# TODO(#973): Fix app module tests for Robolectric. -app_test( - name = "InputInteractionViewTestActivityTest", - srcs = [test_with_resources("src/sharedTest/java/org/oppia/android/app/testing/InputInteractionViewTestActivityTest.kt")], - test_class = "org.oppia.android.app.testing.InputInteractionViewTestActivityTest", - deps = TEST_DEPS, -) - -# TODO(#973): Fix app module tests for Robolectric. -app_test( - name = "NavigationDrawerActivityTest", - srcs = [test_with_resources("src/sharedTest/java/org/oppia/android/app/testing/NavigationDrawerActivityTest.kt")], - test_class = "org.oppia.android.app.testing.NavigationDrawerActivityTest", - deps = TEST_DEPS, -) - -app_test( - name = "TestFontScaleConfigurationUtilActivityTest", - srcs = [test_with_resources("src/sharedTest/java/org/oppia/android/app/testing/TestFontScaleConfigurationUtilActivityTest.kt")], - test_class = "org.oppia.android.app.testing.TestFontScaleConfigurationUtilActivityTest", - deps = TEST_DEPS, -) - -app_test( - name = "TopicTestActivityForStoryTest", - srcs = [test_with_resources("src/sharedTest/java/org/oppia/android/app/testing/TopicTestActivityForStoryTest.kt")], - test_class = "org.oppia.android.app.testing.TopicTestActivityForStoryTest", - deps = TEST_DEPS, -) - -app_test( - name = "TopicFragmentTest", - srcs = [test_with_resources("src/sharedTest/java/org/oppia/android/app/topic/TopicFragmentTest.kt")], - test_class = "org.oppia.android.app.topic.TopicFragmentTest", - deps = TEST_DEPS, -) - -app_test( - name = "ConceptCardFragmentTest", - srcs = [test_with_resources("src/sharedTest/java/org/oppia/android/app/topic/conceptcard/ConceptCardFragmentTest.kt")], - test_class = "org.oppia.android.app.topic.conceptcard.ConceptCardFragmentTest", - deps = TEST_DEPS, -) - -app_test( - name = "TopicInfoFragmentTest", - srcs = [test_with_resources("src/sharedTest/java/org/oppia/android/app/topic/info/TopicInfoFragmentTest.kt")], - test_class = "org.oppia.android.app.topic.info.TopicInfoFragmentTest", - deps = TEST_DEPS, -) - -app_test( - name = "TopicLessonsFragmentTest", - srcs = [test_with_resources("src/sharedTest/java/org/oppia/android/app/topic/lessons/TopicLessonsFragmentTest.kt")], - test_class = "org.oppia.android.app.topic.lessons.TopicLessonsFragmentTest", - deps = TEST_DEPS, -) - -app_test( - name = "TopicPracticeFragmentTest", - srcs = [test_with_resources("src/sharedTest/java/org/oppia/android/app/topic/practice/TopicPracticeFragmentTest.kt")], - test_class = "org.oppia.android.app.topic.practice.TopicPracticeFragmentTest", - deps = TEST_DEPS, -) - -app_test( - name = "QuestionPlayerActivityTest", - srcs = [test_with_resources("src/sharedTest/java/org/oppia/android/app/topic/questionplayer/QuestionPlayerActivityTest.kt")], - test_class = "org.oppia.android.app.topic.questionplayer.QuestionPlayerActivityTest", - deps = TEST_DEPS, -) - -app_test( - name = "TopicRevisionFragmentTest", - srcs = [test_with_resources("src/sharedTest/java/org/oppia/android/app/topic/revision/TopicRevisionFragmentTest.kt")], - test_class = "org.oppia.android.app.topic.revision.TopicRevisionFragmentTest", - deps = TEST_DEPS, -) - -app_test( - name = "RevisionCardFragmentTest", - srcs = [test_with_resources("src/sharedTest/java/org/oppia/android/app/topic/revisioncard/RevisionCardFragmentTest.kt")], - test_class = "org.oppia.android.app.topic.revisioncard.RevisionCardFragmentTest", - deps = TEST_DEPS, -) - -app_test( - name = "WalkthroughActivityTest", - srcs = [test_with_resources("src/sharedTest/java/org/oppia/android/app/walkthrough/WalkthroughActivityTest.kt")], - test_class = "org.oppia.android.app.walkthrough.WalkthroughActivityTest", - deps = TEST_DEPS, -) - -app_test( - name = "WalkthroughFinalFragmentTest", - srcs = [test_with_resources("src/sharedTest/java/org/oppia/android/app/walkthrough/WalkthroughFinalFragmentTest.kt")], - test_class = "org.oppia.android.app.walkthrough.WalkthroughFinalFragmentTest", - deps = TEST_DEPS, -) - -app_test( - name = "WalkthroughTopicListFragmentTest", - srcs = [test_with_resources("src/sharedTest/java/org/oppia/android/app/walkthrough/WalkthroughTopicListFragmentTest.kt")], - test_class = "org.oppia.android.app.walkthrough.WalkthroughTopicListFragmentTest", - deps = TEST_DEPS, -) - -app_test( - name = "WalkthroughWelcomeFragmentTest", - srcs = [test_with_resources("src/sharedTest/java/org/oppia/android/app/walkthrough/WalkthroughWelcomeFragmentTest.kt")], - test_class = "org.oppia.android.app.walkthrough.WalkthroughWelcomeFragmentTest", +# Shared tests. +[app_test( + name = test_file_path, + filtered_tests = MIGRATED_TESTS, + manifest_values = { + "applicationId": "org.oppia.android", + "minSdkVersion": "19", + "targetSdkVersion": "28", + "versionCode": "0", + "versionName": "0.1-alpha", + }, + processed_src = test_with_resources(test_file_path), + test_path_prefix = "src/sharedTest/java/", deps = TEST_DEPS, -) +) for test_file_path in glob(["src/sharedTest/java/org/oppia/android/app/**/*Test.kt"])] # TODO(#1566): Move Firebase rules to their own package & remove default visibility # Package for all Firebase dependencies. diff --git a/app/app_test.bzl b/app/app_test.bzl index a7a38c9fdc1..4d76856ae10 100644 --- a/app/app_test.bzl +++ b/app/app_test.bzl @@ -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 ) diff --git a/app/src/test/java/org/oppia/android/app/testing/options/OptionsFragmentTest.kt b/app/src/test/java/org/oppia/android/app/testing/options/OptionsFragmentTest.kt index 82f75e83b16..d3067bcf4a2 100644 --- a/app/src/test/java/org/oppia/android/app/testing/options/OptionsFragmentTest.kt +++ b/app/src/test/java/org/oppia/android/app/testing/options/OptionsFragmentTest.kt @@ -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 { @@ -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)) } } @@ -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)) } } @@ -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)) } } diff --git a/app/test_with_resources.bzl b/app/test_with_resources.bzl index 9dcb5b1c0d9..7c4ccb72341 100644 --- a/app/test_with_resources.bzl +++ b/app/test_with_resources.bzl @@ -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], diff --git a/domain/BUILD.bazel b/domain/BUILD.bazel index e27a74b9b65..1a6742bb96b 100755 --- a/domain/BUILD.bazel +++ b/domain/BUILD.bazel @@ -65,437 +65,16 @@ TEST_DEPS = [ "//third_party:robolectric_android-all", ] -domain_test( - name = "AudioPlayerControllerTest", - srcs = ["src/test/java/org/oppia/android/domain/audio/AudioPlayerControllerTest.kt"], - test_class = "org.oppia.android.domain.audio.AudioPlayerControllerTest", - deps = TEST_DEPS, -) - -domain_test( - name = "CellularAudioDialogControllerTest", - srcs = ["src/test/java/org/oppia/android/domain/audio/CellularAudioDialogControllerTest.kt"], - test_class = "org.oppia.android.domain.audio.CellularAudioDialogControllerTest", - deps = TEST_DEPS, -) - -domain_test( - name = "AnswerClassificationControllerTest", - srcs = ["src/test/java/org/oppia/android/domain/classify/AnswerClassificationControllerTest.kt"], - test_class = "org.oppia.android.domain.classify.AnswerClassificationControllerTest", - deps = TEST_DEPS, -) - -domain_test( - name = "NumericInputEqualsRuleClassifierProviderTest", - srcs = ["src/test/java/org/oppia/android/domain/classify/rules/numericinput/NumericInputEqualsRuleClassifierProviderTest.kt"], - test_class = "org.oppia.android.domain.classify.rules.numericinput.NumericInputEqualsRuleClassifierProviderTest", - deps = TEST_DEPS, -) - -domain_test( - name = "NumericInputIsGreaterThanOrEqualToRuleClassifierProviderTest", - srcs = ["src/test/java/org/oppia/android/domain/classify/rules/numericinput/NumericInputIsGreaterThanOrEqualToRuleClassifierProviderTest.kt"], - test_class = "org.oppia.android.domain.classify.rules.numericinput.NumericInputIsGreaterThanOrEqualToRuleClassifierProviderTest", - deps = TEST_DEPS, -) - -domain_test( - name = "NumericInputIsGreaterThanRuleClassifierProviderTest", - srcs = ["src/test/java/org/oppia/android/domain/classify/rules/numericinput/NumericInputIsGreaterThanRuleClassifierProviderTest.kt"], - test_class = "org.oppia.android.domain.classify.rules.numericinput.NumericInputIsGreaterThanRuleClassifierProviderTest", - deps = TEST_DEPS, -) - -domain_test( - name = "NumericInputIsInclusivelyBetweenRuleClassifierProviderTest", - srcs = ["src/test/java/org/oppia/android/domain/classify/rules/numericinput/NumericInputIsInclusivelyBetweenRuleClassifierProviderTest.kt"], - test_class = "org.oppia.android.domain.classify.rules.numericinput.NumericInputIsInclusivelyBetweenRuleClassifierProviderTest", - deps = TEST_DEPS, -) - -domain_test( - name = "NumericInputIsLessThanOrEqualToRuleClassifierProviderTest", - srcs = ["src/test/java/org/oppia/android/domain/classify/rules/numericinput/NumericInputIsLessThanOrEqualToRuleClassifierProviderTest.kt"], - test_class = "org.oppia.android.domain.classify.rules.numericinput.NumericInputIsLessThanOrEqualToRuleClassifierProviderTest", - deps = TEST_DEPS, -) - -domain_test( - name = "NumericInputIsLessThanRuleClassifierProviderTest", - srcs = ["src/test/java/org/oppia/android/domain/classify/rules/numericinput/NumericInputIsLessThanRuleClassifierProviderTest.kt"], - test_class = "org.oppia.android.domain.classify.rules.numericinput.NumericInputIsLessThanRuleClassifierProviderTest", - deps = TEST_DEPS, -) - -domain_test( - name = "NumericInputIsWithinToleranceRuleClassifierProviderTest", - srcs = ["src/test/java/org/oppia/android/domain/classify/rules/numericinput/NumericInputIsWithinToleranceRuleClassifierProviderTest.kt"], - test_class = "org.oppia.android.domain.classify.rules.numericinput.NumericInputIsWithinToleranceRuleClassifierProviderTest", - deps = TEST_DEPS, -) - -domain_test( - name = "RatioInputEqualsRuleClassifierProviderTest", - srcs = ["src/test/java/org/oppia/android/domain/classify/rules/ratioinput/RatioInputEqualsRuleClassifierProviderTest.kt"], - test_class = "org.oppia.android.domain.classify.rules.ratioinput.RatioInputEqualsRuleClassifierProviderTest", - deps = TEST_DEPS, -) - -domain_test( - name = "RatioInputHasNumberOfTermsEqualToClassifierProviderTest", - srcs = ["src/test/java/org/oppia/android/domain/classify/rules/ratioinput/RatioInputHasNumberOfTermsEqualToClassifierProviderTest.kt"], - test_class = "org.oppia.android.domain.classify.rules.ratioinput.RatioInputHasNumberOfTermsEqualToClassifierProviderTest", - deps = TEST_DEPS, -) - -domain_test( - name = "RatioInputIsEquivalentRuleClassifierProviderTest", - srcs = ["src/test/java/org/oppia/android/domain/classify/rules/ratioinput/RatioInputIsEquivalentRuleClassifierProviderTest.kt"], - test_class = "org.oppia.android.domain.classify.rules.ratioinput.RatioInputIsEquivalentRuleClassifierProviderTest", - deps = TEST_DEPS, -) - -domain_test( - name = "DragDropSortInputHasElementXAtPositionYRuleClassifierProviderTest", - srcs = [ - "src/test/java/org/oppia/android/domain/classify/rules/dragAndDropSortInput/DragDropSortInputHasElementXAtPositionYRuleClassifierProviderTest.kt", - ], - test_class = "org.oppia.android.domain.classify.rules.dragAndDropSortInput.DragDropSortInputHasElementXAtPositionYRuleClassifierProviderTest", - deps = TEST_DEPS, -) - -domain_test( - name = "DragDropSortInputHasElementXBeforeElementYRuleClassifierProviderTest", - srcs = [ - "src/test/java/org/oppia/android/domain/classify/rules/dragAndDropSortInput/DragDropSortInputHasElementXBeforeElementYRuleClassifierProviderTest.kt", - ], - test_class = "org.oppia.android.domain.classify.rules.dragAndDropSortInput.DragDropSortInputHasElementXBeforeElementYRuleClassifierProviderTest", - deps = TEST_DEPS, -) - -domain_test( - name = "DragDropSortInputIsEqualToOrderingClassifierProviderTest", - srcs = [ - "src/test/java/org/oppia/android/domain/classify/rules/dragAndDropSortInput/DragDropSortInputIsEqualToOrderingClassifierProviderTest.kt", - ], - test_class = "org.oppia.android.domain.classify.rules.dragAndDropSortInput.DragDropSortInputIsEqualToOrderingClassifierProviderTest", - deps = TEST_DEPS, -) - -domain_test( - name = "DragDropSortInputIsEqualToOrderingWithOneItemAtIncorrectPositionClassifierProviderTest", - srcs = [ - "src/test/java/org/oppia/android/domain/classify/rules/dragAndDropSortInput/DragDropSortInputIsEqualToOrderingWithOneItemAtIncorrectPositionClassifierProviderTest.kt", - ], - test_class = "org.oppia.android.domain.classify.rules.dragAndDropSortInput.DragDropSortInputIsEqualToOrderingWithOneItemAtIncorrectPositionClassifierProviderTest", - deps = TEST_DEPS, -) - -domain_test( - name = "FractionInputHasDenominatorEqualToRuleClassifierProviderTest", - srcs = ["src/test/java/org/oppia/android/domain/classify/rules/fractioninput/FractionInputHasDenominatorEqualToRuleClassifierProviderTest.kt"], - test_class = "org.oppia.android.domain.classify.rules.fractioninput.FractionInputHasDenominatorEqualToRuleClassifierProviderTest", - deps = TEST_DEPS, -) - -domain_test( - name = "FractionInputHasFractionalPartExactlyEqualToRuleClassifierProviderTest", - srcs = ["src/test/java/org/oppia/android/domain/classify/rules/fractioninput/FractionInputHasFractionalPartExactlyEqualToRuleClassifierProviderTest.kt"], - test_class = "org.oppia.android.domain.classify.rules.fractioninput.FractionInputHasFractionalPartExactlyEqualToRuleClassifierProviderTest", - deps = TEST_DEPS, -) - -domain_test( - name = "FractionInputHasIntegerPartEqualToRuleClassifierProviderTest", - srcs = ["src/test/java/org/oppia/android/domain/classify/rules/fractioninput/FractionInputHasIntegerPartEqualToRuleClassifierProviderTest.kt"], - test_class = "org.oppia.android.domain.classify.rules.fractioninput.FractionInputHasIntegerPartEqualToRuleClassifierProviderTest", - deps = TEST_DEPS, -) - -domain_test( - name = "FractionInputHasNoFractionalPartRuleClassifierProviderTest", - srcs = ["src/test/java/org/oppia/android/domain/classify/rules/fractioninput/FractionInputHasNoFractionalPartRuleClassifierProviderTest.kt"], - test_class = "org.oppia.android.domain.classify.rules.fractioninput.FractionInputHasNoFractionalPartRuleClassifierProviderTest", - deps = TEST_DEPS, -) - -domain_test( - name = "FractionInputHasNumeratorEqualToRuleClassifierProviderTest", - srcs = ["src/test/java/org/oppia/android/domain/classify/rules/fractioninput/FractionInputHasNumeratorEqualToRuleClassifierProviderTest.kt"], - test_class = "org.oppia.android.domain.classify.rules.fractioninput.FractionInputHasNumeratorEqualToRuleClassifierProviderTest", - deps = TEST_DEPS, -) - -domain_test( - name = "FractionInputIsEquivalentToAndInSimplestFormRuleClassifierProviderTest", - srcs = ["src/test/java/org/oppia/android/domain/classify/rules/fractioninput/FractionInputIsEquivalentToAndInSimplestFormRuleClassifierProviderTest.kt"], - test_class = "org.oppia.android.domain.classify.rules.fractioninput.FractionInputIsEquivalentToAndInSimplestFormRuleClassifierProviderTest", - deps = TEST_DEPS, -) - -domain_test( - name = "FractionInputIsEquivalentToRuleClassifierProviderTest", - srcs = ["src/test/java/org/oppia/android/domain/classify/rules/fractioninput/FractionInputIsEquivalentToRuleClassifierProviderTest.kt"], - test_class = "org.oppia.android.domain.classify.rules.fractioninput.FractionInputIsEquivalentToRuleClassifierProviderTest", - deps = TEST_DEPS, -) - -domain_test( - name = "FractionInputIsExactlyEqualToRuleClassifierProviderTest", - srcs = ["src/test/java/org/oppia/android/domain/classify/rules/fractioninput/FractionInputIsExactlyEqualToRuleClassifierProviderTest.kt"], - test_class = "org.oppia.android.domain.classify.rules.fractioninput.FractionInputIsExactlyEqualToRuleClassifierProviderTest", - deps = TEST_DEPS, -) - -domain_test( - name = "FractionInputIsGreaterThanRuleClassifierProviderTest", - srcs = ["src/test/java/org/oppia/android/domain/classify/rules/fractioninput/FractionInputIsGreaterThanRuleClassifierProviderTest.kt"], - test_class = "org.oppia.android.domain.classify.rules.fractioninput.FractionInputIsGreaterThanRuleClassifierProviderTest", - deps = TEST_DEPS, -) - -domain_test( - name = "FractionInputIsLessThanRuleClassifierProviderTest", - srcs = ["src/test/java/org/oppia/android/domain/classify/rules/fractioninput/FractionInputIsLessThanRuleClassifierProviderTest.kt"], - test_class = "org.oppia.android.domain.classify.rules.fractioninput.FractionInputIsLessThanRuleClassifierProviderTest", - deps = TEST_DEPS, -) - -domain_test( - name = "ImageClickInputIsInRegionRuleClassifierProviderTest", - srcs = [ - "src/test/java/org/oppia/android/domain/classify/rules/imageClickInput/ImageClickInputIsInRegionRuleClassifierProviderTest.kt", - ], - test_class = "org.oppia.android.domain.classify.rules.imageClickInput.ImageClickInputIsInRegionRuleClassifierProviderTest", - deps = TEST_DEPS, -) - -domain_test( - name = "ItemSelectionInputContainsAtLeastOneOfRuleClassifierProviderTest", - srcs = [ - "src/test/java/org/oppia/android/domain/classify/rules/itemselectioninput/ItemSelectionInputContainsAtLeastOneOfRuleClassifierProviderTest.kt", - ], - test_class = "org.oppia.android.domain.classify.rules.itemselectioninput.ItemSelectionInputContainsAtLeastOneOfRuleClassifierProviderTest", - deps = TEST_DEPS, -) - -domain_test( - name = "ItemSelectionInputIsProperSubsetOfRuleClassifierProviderTest", - srcs = [ - "src/test/java/org/oppia/android/domain/classify/rules/itemselectioninput/ItemSelectionInputIsProperSubsetOfRuleClassifierProviderTest.kt", - ], - test_class = "org.oppia.android.domain.classify.rules.itemselectioninput.ItemSelectionInputIsProperSubsetOfRuleClassifierProviderTest", - deps = TEST_DEPS, -) - -domain_test( - name = "ItemsSelectionInputEqualsRuleClassifierProviderTest", - srcs = [ - "src/test/java/org/oppia/android/domain/classify/rules/itemselectioninput/ItemsSelectionInputEqualsRuleClassifierProviderTest.kt", - ], - test_class = "org.oppia.android.domain.classify.rules.itemselectioninput.ItemsSelectionInputEqualsRuleClassifierProviderTest", - deps = TEST_DEPS, -) - -domain_test( - name = "ItemSelectionInputDoesNotContainAtLeastOneOfRuleClassifierProviderTest", - srcs = [ - "src/test/java/org/oppia/android/domain/classify/rules/itemselectioninput/ItemSelectionInputDoesNotContainAtLeastOneOfRuleClassifierProviderTest.kt", - ], - test_class = "org.oppia.android.domain.classify.rules.itemselectioninput.ItemSelectionInputDoesNotContainAtLeastOneOfRuleClassifierProviderTest", - deps = TEST_DEPS, -) - -domain_test( - name = "MultipleChoiceInputEqualsRuleClassifierProviderTest", - srcs = [ - "src/test/java/org/oppia/android/domain/classify/rules/multiplechoiceinput/MultipleChoiceInputEqualsRuleClassifierProviderTest.kt", - ], - test_class = "org.oppia.android.domain.classify.rules.multiplechoiceinput.MultipleChoiceInputEqualsRuleClassifierProviderTest", - deps = TEST_DEPS, -) - -domain_test( - name = "NumberWithUnitsIsEqualToRuleClassifierProviderTest", - srcs = [ - "src/test/java/org/oppia/android/domain/classify/rules/numberwithunits/NumberWithUnitsIsEqualToRuleClassifierProviderTest.kt", - ], - test_class = "org.oppia.android.domain.classify.rules.numberwithunits.NumberWithUnitsIsEqualToRuleClassifierProviderTest", - deps = TEST_DEPS, -) - -domain_test( - name = "NumberWithUnitsIsEquivalentToRuleClassifierProviderTest", - srcs = [ - "src/test/java/org/oppia/android/domain/classify/rules/numberwithunits/NumberWithUnitsIsEquivalentToRuleClassifierProviderTest.kt", - ], - test_class = "org.oppia.android.domain.classify.rules.numberwithunits.NumberWithUnitsIsEquivalentToRuleClassifierProviderTest", - deps = TEST_DEPS, -) - -domain_test( - name = "TextInputCaseSensitiveEqualsRuleClassifierProviderTest", - srcs = [ - "src/test/java/org/oppia/android/domain/classify/rules/textinput/TextInputCaseSensitiveEqualsRuleClassifierProviderTest.kt", - ], - test_class = "org.oppia.android.domain.classify.rules.textinput.TextInputCaseSensitiveEqualsRuleClassifierProviderTest", - deps = TEST_DEPS, -) - -domain_test( - name = "TextInputContainsRuleClassifierProviderTest", - srcs = [ - "src/test/java/org/oppia/android/domain/classify/rules/textinput/TextInputContainsRuleClassifierProviderTest.kt", - ], - test_class = "org.oppia.android.domain.classify.rules.textinput.TextInputContainsRuleClassifierProviderTest", - deps = TEST_DEPS, -) - -domain_test( - name = "TextInputEqualsRuleClassifierProviderTest", - srcs = [ - "src/test/java/org/oppia/android/domain/classify/rules/textinput/TextInputEqualsRuleClassifierProviderTest.kt", - ], - test_class = "org.oppia.android.domain.classify.rules.textinput.TextInputEqualsRuleClassifierProviderTest", - deps = TEST_DEPS, -) - -domain_test( - name = "TextInputFuzzyEqualsRuleClassifierProviderTest", - srcs = [ - "src/test/java/org/oppia/android/domain/classify/rules/textinput/TextInputFuzzyEqualsRuleClassifierProviderTest.kt", - ], - test_class = "org.oppia.android.domain.classify.rules.textinput.TextInputFuzzyEqualsRuleClassifierProviderTest", - deps = TEST_DEPS, -) - -domain_test( - name = "TextInputStartsWithRuleClassifierProviderTest", - srcs = [ - "src/test/java/org/oppia/android/domain/classify/rules/textinput/TextInputStartsWithRuleClassifierProviderTest.kt", - ], - test_class = "org.oppia.android.domain.classify.rules.textinput.TextInputStartsWithRuleClassifierProviderTest", - deps = TEST_DEPS, -) - -domain_test( - name = "ExplorationDataControllerTest", - srcs = ["src/test/java/org/oppia/android/domain/exploration/ExplorationDataControllerTest.kt"], - test_class = "org.oppia.android.domain.exploration.ExplorationDataControllerTest", - deps = TEST_DEPS, -) - -domain_test( - name = "ExplorationProgressControllerTest", - srcs = ["src/test/java/org/oppia/android/domain/exploration/ExplorationProgressControllerTest.kt"], - test_class = "org.oppia.android.domain.exploration.ExplorationProgressControllerTest", - deps = TEST_DEPS, -) - -domain_test( - name = "AppStartupStateControllerTest", - srcs = ["src/test/java/org/oppia/android/domain/onboarding/AppStartupStateControllerTest.kt"], - test_class = "org.oppia.android.domain.onboarding.AppStartupStateControllerTest", - deps = TEST_DEPS, -) - -domain_test( - name = "AnalyticsControllerTest", - srcs = ["src/test/java/org/oppia/android/domain/oppialogger/analytics/AnalyticsControllerTest.kt"], - test_class = "org.oppia.android.domain.oppialogger.analytics.AnalyticsControllerTest", - deps = TEST_DEPS, -) - -domain_test( - name = "UncaughtExceptionLoggerStartupListenerTest", - srcs = ["src/test/java/org/oppia/android/domain/oppialogger/exceptions/UncaughtExceptionLoggerStartupListenerTest.kt"], - test_class = "org.oppia.android.domain.oppialogger.exceptions.UncaughtExceptionLoggerStartupListenerTest", - deps = TEST_DEPS, -) - -domain_test( - name = "LogUploadWorkerTest", - srcs = ["src/test/java/org/oppia/android/domain/oppialogger/loguploader/LogUploadWorkerTest.kt"], - test_class = "org.oppia.android.domain.oppialogger.loguploader.LogUploadWorkerTest", - deps = TEST_DEPS, -) - -domain_test( - name = "OppiaLoggerTest", - srcs = ["src/test/java/org/oppia/android/domain/oppialogger/OppiaLoggerTest.kt"], - test_class = "org.oppia.android.domain.oppialogger.OppiaLoggerTest", - deps = TEST_DEPS, -) - -domain_test( - name = "ProfileManagementControllerTest", - srcs = ["src/test/java/org/oppia/android/domain/profile/ProfileManagementControllerTest.kt"], - test_class = "org.oppia.android.domain.profile.ProfileManagementControllerTest", - deps = TEST_DEPS, -) - -domain_test( - name = "QuestionAssessmentProgressControllerTest", - srcs = ["src/test/java/org/oppia/android/domain/question/QuestionAssessmentProgressControllerTest.kt"], - test_class = "org.oppia.android.domain.question.QuestionAssessmentProgressControllerTest", - deps = TEST_DEPS, -) - -domain_test( - name = "QuestionTrainingControllerTest", - srcs = ["src/test/java/org/oppia/android/domain/question/QuestionTrainingControllerTest.kt"], - test_class = "org.oppia.android.domain.question.QuestionTrainingControllerTest", - deps = TEST_DEPS, -) - -domain_test( - name = "StoryProgressControllerTest", - srcs = ["src/test/java/org/oppia/android/domain/topic/StoryProgressControllerTest.kt"], - test_class = "org.oppia.android.domain.topic.StoryProgressControllerTest", - deps = TEST_DEPS, -) - -domain_test( - name = "TopicControllerTest", - srcs = ["src/test/java/org/oppia/android/domain/topic/TopicControllerTest.kt"], - test_class = "org.oppia.android.domain.topic.TopicControllerTest", - deps = TEST_DEPS, -) - -domain_test( - name = "TopicListControllerTest", - srcs = ["src/test/java/org/oppia/android/domain/topic/TopicListControllerTest.kt"], - test_class = "org.oppia.android.domain.topic.TopicListControllerTest", - deps = TEST_DEPS, -) - -domain_test( - name = "InteractionObjectExtensionsTest", - srcs = ["src/test/java/org/oppia/android/domain/util/InteractionObjectExtensionsTest.kt"], - test_class = "org.oppia.android.domain.util.InteractionObjectExtensionsTest", - deps = TEST_DEPS, -) - -domain_test( - name = "RatioExtensionsTest", - srcs = ["src/test/java/org/oppia/android/domain/util/RatioExtensionsTest.kt"], - test_class = "org.oppia.android.domain.util.RatioExtensionsTest", - deps = TEST_DEPS, -) - -domain_test( - name = "StateRetrieverTest", - srcs = ["src/test/java/org/oppia/android/domain/util/StateRetrieverTest.kt"], - test_class = "org.oppia.android.domain.util.StateRetrieverTest", - deps = TEST_DEPS, -) +# Qualified file paths for test classes that have been migrated over to their own packages & +# shouldn't be defined as module-level tests. +# keep sorted +MIGRATED_TESTS = [ +] -domain_test( - name = "StringExtensionsTest", - srcs = ["src/test/java/org/oppia/android/domain/util/StringExtensionsTest.kt"], - test_class = "org.oppia.android.domain.util.StringExtensionsTest", +[domain_test( + name = test_file_path, + filtered_tests = MIGRATED_TESTS, deps = TEST_DEPS, -) +) for test_file_path in glob(["src/test/java/org/oppia/android/domain/**/*Test.kt"])] dagger_rules() diff --git a/domain/domain_test.bzl b/domain/domain_test.bzl index eeaf5fbebad..e574cd7c87d 100644 --- a/domain/domain_test.bzl +++ b/domain/domain_test.bzl @@ -2,26 +2,24 @@ Macros for domain 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 domain_test(name, srcs, test_class, deps): - # Creates individual tests for test files in the domain module. - # - # Args: - # name: str. The name of the Kotlin test file without the '.kt' suffix. - # srcs: 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 'AsyncResultTest.kt', - # then the test_class would be "org.oppia.util.data.AsyncResultTest". - # deps: list of str. The list of dependencies needed to build and run this test. +def domain_test(name, filtered_tests, deps): + """ + Creates individual tests for test files in the domain module. - oppia_android_test( + Args: + name: str. The relative path to the Kotlin test file. + 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. + """ + oppia_android_module_level_test( name = name, - srcs = srcs, + filtered_tests = filtered_tests, + deps = deps, custom_package = "org.oppia.android.domain", - test_class = test_class, test_manifest = "src/test/AndroidManifest.xml", assets = native.glob(["src/main/assets/**"]), assets_dir = "src/main/assets/", - deps = deps, ) diff --git a/domain/src/test/java/org/oppia/android/domain/oppialogger/exceptions/ExceptionsControllerTest.kt b/domain/src/test/java/org/oppia/android/domain/oppialogger/exceptions/ExceptionsControllerTest.kt index 3f91343bd83..81c9bee59ac 100644 --- a/domain/src/test/java/org/oppia/android/domain/oppialogger/exceptions/ExceptionsControllerTest.kt +++ b/domain/src/test/java/org/oppia/android/domain/oppialogger/exceptions/ExceptionsControllerTest.kt @@ -126,11 +126,18 @@ class ExceptionsControllerTest { val exceptionLog = oppiaExceptionLogsResultCaptor.value.getOrThrow().getExceptionLog(0) val exception = exceptionLog.toException() + val thrownExceptionStackTraceElems = exception.stackTrace.extractRelevantDetails() + val thrownCauseExceptionStackTraceElems = exception.cause?.stackTrace?.extractRelevantDetails() + val expectedExceptionStackTraceElems = exceptionThrown.stackTrace.extractRelevantDetails() + val expectedCauseExceptionStackTraceElems = + exceptionThrown.cause?.stackTrace?.extractRelevantDetails() assertThat(exception.message).isEqualTo(exceptionThrown.message) - assertThat(exception.stackTrace).isEqualTo(exceptionThrown.stackTrace) assertThat(exception.cause?.message).isEqualTo(exceptionThrown.cause?.message) - assertThat(exception.cause?.stackTrace).isEqualTo(exceptionThrown.cause?.stackTrace) assertThat(exceptionLog.exceptionType).isEqualTo(ExceptionType.NON_FATAL) + // The following can't be an exact match for the stack trace since new properties are added to + // stack trace elements in newer versions of Java (such as module name). + assertThat(thrownExceptionStackTraceElems).isEqualTo(expectedExceptionStackTraceElems) + assertThat(thrownCauseExceptionStackTraceElems).isEqualTo(expectedCauseExceptionStackTraceElems) } @Test @@ -149,11 +156,18 @@ class ExceptionsControllerTest { val exceptionLog = oppiaExceptionLogsResultCaptor.value.getOrThrow().getExceptionLog(0) val exception = exceptionLog.toException() + val thrownExceptionStackTraceElems = exception.stackTrace.extractRelevantDetails() + val thrownCauseExceptionStackTraceElems = exception.cause?.stackTrace?.extractRelevantDetails() + val expectedExceptionStackTraceElems = exceptionThrown.stackTrace.extractRelevantDetails() + val expectedCauseExceptionStackTraceElems = + exceptionThrown.cause?.stackTrace?.extractRelevantDetails() assertThat(exception.message).isEqualTo(exceptionThrown.message) - assertThat(exception.stackTrace).isEqualTo(exceptionThrown.stackTrace) assertThat(exception.cause?.message).isEqualTo(exceptionThrown.cause?.message) - assertThat(exception.cause?.stackTrace).isEqualTo(exceptionThrown.cause?.stackTrace) assertThat(exceptionLog.exceptionType).isEqualTo(ExceptionType.FATAL) + // The following can't be an exact match for the stack trace since new properties are added to + // stack trace elements in newer versions of Java (such as module name). + assertThat(thrownExceptionStackTraceElems).isEqualTo(expectedExceptionStackTraceElems) + assertThat(thrownCauseExceptionStackTraceElems).isEqualTo(expectedCauseExceptionStackTraceElems) } @Test @@ -249,13 +263,19 @@ class ExceptionsControllerTest { val exceptionFromCacheStorage = oppiaExceptionLogsResultCaptor.value.getOrThrow().getExceptionLog(0) val exception = exceptionFromCacheStorage.toException() - + val thrownExceptionStackTraceElems = exception.stackTrace.extractRelevantDetails() + val thrownCauseExceptionStackTraceElems = exception.cause?.stackTrace?.extractRelevantDetails() + val expectedExceptionStackTraceElems = exceptionThrown.stackTrace.extractRelevantDetails() + val expectedCauseExceptionStackTraceElems = + exceptionThrown.cause?.stackTrace?.extractRelevantDetails() assertThat(exceptionFromRemoteService).isEqualTo(exceptionThrown) assertThat(exception.message).isEqualTo(exceptionThrown.message) - assertThat(exception.stackTrace).isEqualTo(exceptionThrown.stackTrace) assertThat(exception.cause?.message).isEqualTo(exceptionThrown.cause?.message) - assertThat(exception.cause?.stackTrace).isEqualTo(exceptionThrown.cause?.stackTrace) assertThat(exceptionFromCacheStorage.exceptionType).isEqualTo(ExceptionType.FATAL) + // The following can't be an exact match for the stack trace since new properties are added to + // stack trace elements in newer versions of Java (such as module name). + assertThat(thrownExceptionStackTraceElems).isEqualTo(expectedExceptionStackTraceElems) + assertThat(thrownCauseExceptionStackTraceElems).isEqualTo(expectedCauseExceptionStackTraceElems) } @Test @@ -293,10 +313,13 @@ class ExceptionsControllerTest { .onChanged(oppiaExceptionLogsResultCaptor.capture()) val exceptionLog = oppiaExceptionLogsResultCaptor.value.getOrThrow().getExceptionLog(0) val exception = exceptionLog.toException() - + val thrownExceptionStackTraceElems = exception.stackTrace.extractRelevantDetails() + val expectedExceptionStackTraceElems = exceptionThrown.stackTrace.extractRelevantDetails() assertThat(exception.message).isEqualTo(null) - assertThat(exception.stackTrace).isEqualTo(exceptionThrown.stackTrace) assertThat(exception.cause).isEqualTo(null) + // The following can't be an exact match for the stack trace since new properties are added to + // stack trace elements in newer versions of Java (such as module name). + assertThat(thrownExceptionStackTraceElems).isEqualTo(expectedExceptionStackTraceElems) } @Test @@ -314,10 +337,28 @@ class ExceptionsControllerTest { .onChanged(oppiaExceptionLogsResultCaptor.capture()) val exceptionLog = oppiaExceptionLogsResultCaptor.value.getOrThrow().getExceptionLog(0) val exception = exceptionLog.toException() - + val thrownExceptionStackTraceElems = exception.stackTrace.extractRelevantDetails() + val expectedExceptionStackTraceElems = exceptionThrown.stackTrace.extractRelevantDetails() assertThat(exception.message).isEqualTo("TEST") - assertThat(exception.stackTrace).isEqualTo(exceptionThrown.stackTrace) assertThat(exception.cause).isEqualTo(null) + // The following can't be an exact match for the stack trace since new properties are added to + // stack trace elements in newer versions of Java (such as module name). + assertThat(thrownExceptionStackTraceElems).isEqualTo(expectedExceptionStackTraceElems) + } + + /** + * Returns a list of lists of each relevant element of a [StackTraceElement] to be used for + * comparison in a way that's consistent across JDK versions. + */ + private fun Array.extractRelevantDetails(): List> { + return this.map { element -> + return@map listOf( + element.fileName, + element.methodName, + element.lineNumber, + element.className + ) + } } private fun setUpTestApplicationComponent() { diff --git a/model/src/main/proto/format_import_proto_library.bzl b/model/src/main/proto/format_import_proto_library.bzl index 5cf0053a88f..675bb33ea36 100644 --- a/model/src/main/proto/format_import_proto_library.bzl +++ b/model/src/main/proto/format_import_proto_library.bzl @@ -5,18 +5,21 @@ Container for macros to fix proto files. load("@rules_proto//proto:defs.bzl", "proto_library") def format_import_proto_library(name, src, deps): - # This macro exists as a way to build proto files that contain import statements in both Gradle - # and Bazel. - # This macro formats the src file's import statements to contain a full path to the file in order - # for Bazel to properly locate file. - # - # Args: - # name: str. The name of the .proto file without the '.proto' suffix. This will be the root for - # the name of the proto library created. Ex: If name = 'topic', then the src file is - # 'topic.proto' and the proto library created will be named 'topic_proto'. - # src: str. The name of the .proto file to be built into a proto_library. - # deps: list of str. The list of dependencies needed to build the src file. This list will contain - # all of the proto_library targets for the files imported into src. + """ + Creates a new proto library with corrected imports. + + This macro exists as a way to build proto files that contain import statements in both Gradle + and Bazel. This macro formats the src file's import statements to contain a full path to the + file in order for Bazel to properly locate file. + + Args: + name: str. The name of the .proto file without the '.proto' suffix. This will be the root for + the name of the proto library created. Ex: If name = 'topic', then the src file is + 'topic.proto' and the proto library created will be named 'topic_proto'. + src: str. The name of the .proto file to be built into a proto_library. + deps: list of str. The list of dependencies needed to build the src file. This list will + contain all of the proto_library targets for the files imported into src. + """ # TODO(#1543): Ensure this function works on Windows systems. # TODO(#1617): Remove genrules post-gradle diff --git a/oppia_android_test.bzl b/oppia_android_test.bzl index c619980864b..77280daeaf9 100644 --- a/oppia_android_test.bzl +++ b/oppia_android_test.bzl @@ -4,6 +4,38 @@ Central macros pertaining to setting up tests across the codebase. load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_android_library") +# TODO(#1620): Remove module-specific test macros once Gradle is removed +def oppia_android_module_level_test( + name, + filtered_tests, + deps, + processed_src = None, + test_path_prefix = "src/test/java/", + additional_srcs = [], + **kwargs): + """ + Creates individual tests for a test file at the module level. + + Args: + name: str. The relative path to the Kotlin test file. + 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. + 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). + additional_srcs: list of str. Additional source files to build into the test binary. + **kwargs: additional parameters to pass to oppia_android_test. + """ + if name not in filtered_tests: + oppia_android_test( + name = name[:name.find(".kt")], + srcs = [processed_src or name] + additional_srcs, + test_class = _remove_prefix_suffix(name, test_path_prefix, ".kt").replace("/", "."), + deps = deps, + **kwargs + ) + def oppia_android_test( name, srcs, @@ -15,21 +47,24 @@ def oppia_android_test( assets = None, assets_dir = None, **kwargs): - # Creates an Oppia test target for running the specified test as an Android local test with Kotlin - # support. Note that this creates an additional, internal library. - # - # Args: - # name: str. The name of the Kotlin test file without the '.kt' suffix. - # srcs: list of str. The name of the Kotlin test files to be run. - # test_manifest: str. The path to the test manifest file. - # custom_package: str. The module's package. Example: 'org.oppia.utility'. - # test_class: The package of the src file. For example, if the src is 'FakeEventLoggerTest.kt', - # then the test_class would be "org.oppia.testing.FakeEventLoggerTest". - # enable_data_binding: boolean. Indicates whether the test enables data-binding. - # deps: list of str. The list of dependencies needed to run the tests. - # assets: list of str. A list of assets needed to run the tests. - # assets_dir: str. The path to the assets directory. - # kwargs: additional parameters to pass to android_local_test. + """ + Creates a local Oppia test target with Kotlin support. + + Note that this creates an additional, internal library. + + Args: + name: str. The name of the Kotlin test file without the '.kt' suffix. + srcs: list of str. The name of the Kotlin test files to be run. + test_manifest: str. The path to the test manifest file. + custom_package: str. The module's package. Example: 'org.oppia.utility'. + test_class: The package of the src file. For example, if the src is 'FakeEventLoggerTest.kt', + then the test_class would be "org.oppia.testing.FakeEventLoggerTest". + enable_data_binding: boolean. Indicates whether the test enables data-binding. + deps: list of str. The list of dependencies needed to run the tests. + assets: list of str. A list of assets needed to run the tests. + assets_dir: str. The path to the assets directory. + **kwargs: additional parameters to pass to android_local_test. + """ kt_android_library( name = name + "_lib", @@ -50,3 +85,6 @@ def oppia_android_test( deps = [":" + name + "_lib"] + deps, **kwargs ) + +def _remove_prefix_suffix(str, prefix, suffix): + return str[str.find(prefix) + len(prefix):str.find(suffix)] diff --git a/testing/BUILD.bazel b/testing/BUILD.bazel index beb1115787c..08cd8a3a48a 100644 --- a/testing/BUILD.bazel +++ b/testing/BUILD.bazel @@ -55,47 +55,17 @@ TEST_DEPS = [ "//third_party:robolectric_android-all", ] -testing_test( - name = "CoroutineExecutorServiceTest", - srcs = ["src/test/java/org/oppia/android/testing/CoroutineExecutorServiceTest.kt"], - test_class = "org.oppia.android.testing.CoroutineExecutorServiceTest", - deps = TEST_DEPS, -) - -testing_test( - name = "FakeEventLoggerTest", - srcs = ["src/test/java/org/oppia/android/testing/FakeEventLoggerTest.kt"], - test_class = "org.oppia.android.testing.FakeEventLoggerTest", - deps = TEST_DEPS, -) - -testing_test( - name = "FakeExceptionLoggerTest", - srcs = ["src/test/java/org/oppia/android/testing/FakeExceptionLoggerTest.kt"], - test_class = "org.oppia.android.testing.FakeExceptionLoggerTest", - deps = TEST_DEPS, -) - -testing_test( - name = "ProfileTestHelperTest", - srcs = ["src/test/java/org/oppia/android/testing/profile/ProfileTestHelperTest.kt"], - test_class = "org.oppia.android.testing.profile.ProfileTestHelperTest", - deps = TEST_DEPS, -) - -testing_test( - name = "StoryProgressTestHelperTest", - srcs = ["src/test/java/org/oppia/android/testing/story/StoryProgressTestHelperTest.kt"], - test_class = "org.oppia.android.testing.story.StoryProgressTestHelperTest", - deps = TEST_DEPS, -) +# Qualified file paths for test classes that have been migrated over to their own packages & +# shouldn't be defined as module-level tests. +# keep sorted +MIGRATED_TESTS = [ +] -testing_test( - name = "FakeOppiaClockTest", - srcs = ["src/test/java/org/oppia/android/testing/time/FakeOppiaClockTest.kt"], - test_class = "org.oppia.android.testing.time.FakeOppiaClockTest", +[testing_test( + name = test_file_path, + filtered_tests = MIGRATED_TESTS, deps = TEST_DEPS, -) +) for test_file_path in glob(["src/test/java/org/oppia/android/testing/**/*Test.kt"])] kt_android_library( name = "assertion_helpers", diff --git a/testing/testing_test.bzl b/testing/testing_test.bzl index b79954e52a2..e91d2edae78 100644 --- a/testing/testing_test.bzl +++ b/testing/testing_test.bzl @@ -2,24 +2,22 @@ Macros for domain testing 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 testing_test(name, srcs, test_class, deps): - # Creates individual tests for test files in the testing 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. +def testing_test(name, filtered_tests, deps): + """ + Creates individual tests for test files in the testing module. - oppia_android_test( + Args: + name: str. The relative path to the Kotlin test file. + 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. + """ + oppia_android_module_level_test( name = name, - srcs = srcs, + filtered_tests = filtered_tests, + deps = deps, custom_package = "org.oppia.android.testing", - test_class = test_class, test_manifest = "src/test/AndroidManifest.xml", - deps = deps, ) diff --git a/utility/BUILD.bazel b/utility/BUILD.bazel index 30b8f2549a6..7069cdf0c19 100644 --- a/utility/BUILD.bazel +++ b/utility/BUILD.bazel @@ -38,6 +38,7 @@ TEST_DEPS = [ "//app:crashlytics", "//app:crashlytics_deps", "//model", + "//model:test_models", "//testing", "//third_party:androidx_test_ext_junit", "//third_party:com_google_truth_truth", @@ -47,69 +48,16 @@ TEST_DEPS = [ "//third_party:robolectric_android-all", ] -utility_test( - name = "AsyncResultTest", - srcs = ["src/test/java/org/oppia/android/util/data/AsyncResultTest.kt"], - test_class = "org.oppia.android.util.data.AsyncResultTest", - deps = TEST_DEPS, -) - -utility_test( - name = "DataProvidersTest", - srcs = ["src/test/java/org/oppia/android/util/data/DataProvidersTest.kt"], - test_class = "org.oppia.android.util.data.DataProvidersTest", - deps = TEST_DEPS, -) - -utility_test( - name = "InMemoryBlockingCacheTest", - srcs = ["src/test/java/org/oppia/android/util/data/InMemoryBlockingCacheTest.kt"], - test_class = "org.oppia.android.util.data.InMemoryBlockingCacheTest", - deps = TEST_DEPS, -) - -utility_test( - name = "DateTimeUtilTest", - srcs = ["src/test/java/org/oppia/android/util/datetime/DateTimeUtilTest.kt"], - test_class = "org.oppia.android.util.datetime.DateTimeUtilTest", - deps = TEST_DEPS, -) - -utility_test( - name = "BundleExtensionsTest", - srcs = ["src/test/java/org/oppia/android/util/extensions/BundleExtensionsTest.kt"], - test_class = "org.oppia.android.util.extensions.BundleExtensionsTest", - deps = TEST_DEPS + [ - "//model:test_models", - ], -) - -utility_test( - name = "EventBundleCreatorTest", - srcs = ["src/test/java/org/oppia/android/util/logging/EventBundleCreatorTest.kt"], - test_class = "org.oppia.android.util.logging.EventBundleCreatorTest", - deps = TEST_DEPS, -) - -utility_test( - name = "NetworkConnectionUtilTest", - srcs = ["src/test/java/org/oppia/android/util/networking/NetworkConnectionUtilTest.kt"], - test_class = "org.oppia.android.util.networking.NetworkConnectionUtilTest", - deps = TEST_DEPS, -) - -utility_test( - name = "DirectoryManagementUtilTest", - srcs = ["src/test/java/org/oppia/android/util/profile/DirectoryManagementUtilTest.kt"], - test_class = "org.oppia.android.util.profile.DirectoryManagementUtilTest", - deps = TEST_DEPS, -) +# Qualified file paths for test classes that have been migrated over to their own packages & +# shouldn't be defined as module-level tests. +# keep sorted +MIGRATED_TESTS = [ +] -utility_test( - name = "OppiaDateTimeFormatterTest", - srcs = ["src/test/java/org/oppia/android/util/system/OppiaDateTimeFormatterTest.kt"], - test_class = "org.oppia.android.util.system.OppiaDateTimeFormatterTest", +[utility_test( + name = test_file_path, + filtered_tests = MIGRATED_TESTS, deps = TEST_DEPS, -) +) for test_file_path in glob(["src/test/java/org/oppia/android/util/**/*Test.kt"])] dagger_rules() diff --git a/utility/utility_test.bzl b/utility/utility_test.bzl index 7371771852f..469850080ff 100644 --- a/utility/utility_test.bzl +++ b/utility/utility_test.bzl @@ -2,23 +2,22 @@ Macros for utility 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 utility_test(name, srcs, test_class, deps): - # Creates individual tests for test files in the utility module. - # Args: - # name: str. The name of the Kotlin test file without the '.kt' suffix. - # srcs: 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 'AsyncResultTest.kt', - # then the test_class would be "org.oppia.util.data.AsyncResultTest". - # deps: list of str. The list of dependencies needed to build and run this test. +def utility_test(name, filtered_tests, deps): + """ + Creates individual tests for test files in the utility module. - oppia_android_test( + Args: + name: str. The relative path to the Kotlin test file. + 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. + """ + oppia_android_module_level_test( name = name, - srcs = srcs, + filtered_tests = filtered_tests, + deps = deps, custom_package = "org.oppia.android.util", - test_class = test_class, test_manifest = "src/test/AndroidManifest.xml", - deps = deps, )