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

Fixes part of #59: Introduce app module Robolectric tests + Bazel [BLOCKED: #1622] #1634

Merged
merged 454 commits into from
Aug 22, 2020

Conversation

miaboloix
Copy link
Contributor

@miaboloix miaboloix commented Aug 12, 2020

Explanation

Fixes part of #59: Introduce app module Robolectric tests + Bazel [BLOCKED: #1622]

This PR sets up Robolectric tests for app module + Bazel. Because rules_kotlin does not have a kt_android_local_test rule, each test must be built in it's own kt_android_library and fed into an android_local_test rule as a dependency - the macro file app_tests.bzl handles this. On top of this, certain necessary data binding processing is not being handled by kt_android_library and android_local_test, causing DataBinderMapperImpl.java not to be generated. The workaround for this is manually creating DataBinderMapperImpl.java and adding it to the source file list for each test target.

In order to set up the correct version of Bazel, please follow the instructions laid out in this document.

To build and run all the tests in app module, run

~/oppia-bazel/bazel-bin/src/bazel test //app/... --android_databinding_use_v3_4_args --experimental_android_databinding_v2 --override_repository=android_tools=/tmp/android_tools --subcommands --java_header_compilation=false --noincremental_dexing --define=android_standalone_dexing_tool=d8_compat_dx

To build and run a specific test in app module, run

~/oppia-bazel/bazel-bin/src/bazel test //app:<name_of_test> --android_databinding_use_v3_4_args --experimental_android_databinding_v2 --override_repository=android_tools=/tmp/android_tools --subcommands --java_header_compilation=false --noincremental_dexing --define=android_standalone_dexing_tool=d8_compat_dx

Checklist

  • The PR title starts with "Fix #bugnum: ", followed by a short, clear summary of the changes. (If this PR fixes part of an issue, prefix the title with "Fix part of #bugnum: ...".)
  • The PR explanation includes the words "Fixes #bugnum: ..." (or "Fixes part of #bugnum" if the PR only partially fixes an issue).
  • The PR follows the style guide.
  • The PR does not contain any unnecessary auto-generated code from Android Studio.
  • The PR is made from a branch that's not called "develop".
  • The PR is made from a branch that is up-to-date with "develop".
  • The PR's branch is based on "develop" and not on any other branch.
  • The PR is assigned to an appropriate reviewer in both the Assignees and the Reviewers sections.

Copy link
Sponsor Member

@BenHenning BenHenning left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing 'approved' per the incorrect @Inject.

@miaboloix miaboloix assigned BenHenning and unassigned miaboloix Aug 21, 2020
Copy link
Sponsor Member

@BenHenning BenHenning left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @miaboloix. LGTM!

@BenHenning BenHenning removed their assignment Aug 21, 2020
Base automatically changed from build-app-library-binary-bazel to develop August 22, 2020 03:37
@miaboloix miaboloix merged commit 8cacffb into develop Aug 22, 2020
@miaboloix miaboloix deleted the introduce-robolctric-app-tests branch August 22, 2020 03:57
miaboloix added a commit that referenced this pull request Aug 22, 2020
…1679)

* Translated RecyclerViewBindingAdapter

* Deleted kotlin binding adapters

* Translated GuidelineBindingAdapter

* Translated StateAssemblerMarginBindingAdapters

* Translated StateAssemblerPaddingBindingAdapters

* Almost finished translating ViewBindingAdapter

* Fixed the duplicate google-services.json issue

* Created Issue and added TODO

* Translated ViewBindingAdapter

* Added minSDK back

* Alphabetized dependencies

* Fixed firebase target

* Trying to fix StateRetreiverTest

* Binding Adapter files are building with Gradle!

* Fixed ktlint violation

* Revert "Deleted kotlin binding adapters"

This reverts commit 84037cb.

* Revert "Translated GuidelineBindingAdapter"

This reverts commit ce92d0a.

* Revert "Translated StateAssemblerMarginBindingAdapters"

This reverts commit 88c9492.

* Revert "Translated StateAssemblerPaddingBindingAdapters"

This reverts commit d66af07.

* Git mv on DrawableBindingAdapters

* Translated DrawableBindingAdapters

* Deleted java files

* Translated EditTextBA and GuidelineBA

* Translated ImageViewBA

* Added missing semicolon

* Translated MarginBindingAdapters

* Translated State AssemblerMarginBA

* Translated StateAssemblerPaddingBA

* Translated TextViewBA

* Revert "Translated TextViewBA"

This reverts commit 849549d.

* Changed targetSdk to 28

* Revert "Revert "Translated TextViewBA""

This reverts commit 6cfa75d.

* Fixed formatting issues and changed NotNull to NonNull

* Refactored GuidelineBindingAdapter to be GuidelineBindingAdapters

* Fixed some double space errors and other typos

* Added missing ViewBindingAdapter

* Deleted extra spaces and fixed more nit issues

* Made all classes final

* Added top level documentation

* Reformatted some comments to fit java style

* Reformatted imports

* Created Issue and added TODOs for re-restricitng access

* Added min and target SDK to domain manifest

* Added documentation comment

* Deleted unused domain_tests library

* Revert "Deleted unused domain_tests library"

This reverts commit 65e71cc.

* Removed unused domain)tests library

* Annotations and helpers library builds

* Listeners library builds

* View models build

* Views now build

* Added documentation comments

* Started removing binding dependencies from views

* Removed fragment imports used only for comments in order to build view files

* Pulled binding dependenvy out of ConceptCardViewModel

* Edited R import statements for Bazel to build

* Fixed more errors, view_model builds

* Worked through more errors

* Added a dependency

* View library builds

* Ordered BUILD file for better merging

* Both databinding adapters and recyclerview adapters are building

* Starting writing databinding resources library

* Removed unused listeners

* Added missing comments

* Formatted files and added missing @nonnull annotations

* Fixed ktlint errors

* Revert "Formatted files and added missing @nonnull annotations"

This reverts commit 84b6125.

* Added genrule for viewmodel files

* Added view genrule

* Both Bazel and Gradle are building

* Fixed ktlint errors

* Delete vcs.xml

* Renamed files, deleted unused files, and added some documentation

* Improved implementation of some functions in ViewBindingShimImpl and added documentation

* Fixed ktlint errors

* Put genrules in a loop, created issue to remove genrules post-gradle and added TODO

* Added more documentation, created an issue to remove shim files, added TODO

* Fixed Gradle build error

* Added documentation, created an issue, added a TODO

* Formatted single line comments

* Fixing more nits

* Fixed more nits.

* Fixed getTimeAgo() function

* Suppressed warning in bindToRecyclerViewAdapter

* Builds in both Bazel and Gradle

* Added comments to BUILD file

* Fixed profile_chooser_profile_view error

* Fixed profile_chooser_add_view

* Fixed walthrough_final_fragment error

* Fixed profile_chooser_fragment error

* Fixed walthrough_activity error

* Fixed onboarding_fragment error

* Fixed audio_fragment error

* Fixed unused presnter errors, databining resources now build

* Builds with Gradle

* Fixed WalkthroughWelcomeFragmentPresenter to not contain unnecessary methods bc of interface

* Removed unnecessary method from WalkthroughActivity

* Removed the need for ProfileChooserListener, added comments to WalkthroughListeners

* Genrule is working

* Simplified genrule

* Alphabetized lists in app module BUILD

* Quick cleanup, added missing documentation

* App library is building with Bazel

* Added Retrofit+Gson dependency for NetworkModule to build with Gradle

* Binary builds

* Started debugging runtime errors

* Fixed domain BUILD

* Added genrule comments, simplified gnerule targets in lists

* Fixed QuestionPlayerFragmentPresenter and StateFragmentPresenter

* Fixed QuestionPlayerViewModel & FRagmentPresenter as well as StateViewModel & FragmentPresenter

* Fixed some nits

* Fixed ktlint errors

* Added assets

* First test builds and passes

* Fixed DragDrop ViewBinding implementations, added modules to TestComponent

* Fix ktlint errors

* Fixed nits in TextViewBA

* Fixed Audio + Language test appearance bug

* Fixed ktlint errors

* Fixed ktlint error in FAQSingleActivityPresenter

* Fixed ktlin errors

* Cleaned up app BUILD file a bit

* Testing module tests now pass, all domain tests pass except StateRetreiver

* Removed unused dependencies, aplhabetized dependencies

* Fixed list formation

* Cleaned up BUILD

* Fixed nits

* Fixing some nits

* Refactored file names

* Altered walkthrough welcome fragment

* Renamed wasProfileEverBeenAddedValue to hasProfileEverBeenAddedValue

* Fixed ktlint error

* Removed unused dependencies and alphabetized them

* Deleted unused methods in ImageViewBA

* Removed data attribute from domain library

* Excluded DataBinderMapperImpl from Gradle build

* Most tests build and pass

* Started getting sharedTests to run

* All tests now build

* Fixed ktlint errors

* Fixed ktlint error

* Added missing TODOs

* Fixed merge errors

* Fixed nits

* Removed unnecessary field in StateFragmentAccessibilityTest

* Fixed StateFragmentAccessibilityTestFixed StateFragmentAccessibilityTestFixed StateFragmentAccessibilityTestFixed StateFragmentAccessibilityTestFixed StateFragmentAccessibilityTestFixed StateFragmentAccessibilityTestFixed StateFragmentAccessibilityTestFixed StateFragmentAccessibilityTestFixed StateFragmentAccessibilityTest

* Injected context in AppVersionViewModel

* Used lambda function to resolve issues with QuestionPlayerVM and QuestionPlayerFragmentPresenter

* Fixed small errors

* Fixed ktlint errors

* Removed Moshi dependency from NetworkModule

* Fixed ktlint error

* Fixing listener file naming

* Fixed NetworkModule issue by removing it from ApplicationComponent temporarily

* Restored NetworkModule, fixed some nits

* Fixed typo, deleted unused file, removed retrofit gradle dependencies

* Removed NetworkModule from test files, fixed nits, fixed enable_data_binding in oppia_android_test

* Fixing nits

* Fixed more nits

* Fixed StateFragmentPresenter and view model, fixed some nits

* Fixed ktlint errors

* Altered for loop to append directly to DATABINDING_ADAPTERS

* Created issue and added TODO for ApplicationComponent and NetworkModule

* Added TODOs to test files with NetworkModule removed, added documentation to DataBinderMapperImple, fixed nits

* Added documentations, fixed nits

* Added proto optimization

* Fixed nits

* Fixed ktlint error

* Added documentation, fixed nits

* Added a few nits

* Removed unused imports

* Fixed nits

* Created issue, added TODO, updated docs

* Starting to put genrules into a macro

* Fixed documentation

* Added comment about binding adapters in Java

* Created test_with_resources and applied it to tests

* Add more context

* Fixed nits, created a PackageManagerHelper file

* Update WORKSPACE with Markdown

Co-authored-by: Ben Henning <[email protected]>

* Fixed doumenting comment

* Update app/src/main/java/org/oppia/app/utility/PackageManagerHelper.kt

Co-authored-by: Ben Henning <[email protected]>

* Fixed inject issue and nits

* Fixed typo

* Changed filename, included new file in Annotations library

* Fixed lint error

Co-authored-by: Ben Henning <[email protected]>
miaboloix added a commit that referenced this pull request Aug 22, 2020
)

* Fixed the duplicate google-services.json issue

* Created Issue and added TODO

* Translated ViewBindingAdapter

* Added minSDK back

* Alphabetized dependencies

* Fixed firebase target

* Trying to fix StateRetreiverTest

* Binding Adapter files are building with Gradle!

* Fixed ktlint violation

* Revert "Deleted kotlin binding adapters"

This reverts commit 84037cb.

* Revert "Translated GuidelineBindingAdapter"

This reverts commit ce92d0a.

* Revert "Translated StateAssemblerMarginBindingAdapters"

This reverts commit 88c9492.

* Revert "Translated StateAssemblerPaddingBindingAdapters"

This reverts commit d66af07.

* Git mv on DrawableBindingAdapters

* Translated DrawableBindingAdapters

* Deleted java files

* Translated EditTextBA and GuidelineBA

* Translated ImageViewBA

* Added missing semicolon

* Translated MarginBindingAdapters

* Translated State AssemblerMarginBA

* Translated StateAssemblerPaddingBA

* Translated TextViewBA

* Revert "Translated TextViewBA"

This reverts commit 849549d.

* Changed targetSdk to 28

* Revert "Revert "Translated TextViewBA""

This reverts commit 6cfa75d.

* Fixed formatting issues and changed NotNull to NonNull

* Refactored GuidelineBindingAdapter to be GuidelineBindingAdapters

* Fixed some double space errors and other typos

* Added missing ViewBindingAdapter

* Deleted extra spaces and fixed more nit issues

* Made all classes final

* Added top level documentation

* Reformatted some comments to fit java style

* Reformatted imports

* Created Issue and added TODOs for re-restricitng access

* Added min and target SDK to domain manifest

* Added documentation comment

* Deleted unused domain_tests library

* Revert "Deleted unused domain_tests library"

This reverts commit 65e71cc.

* Removed unused domain)tests library

* Annotations and helpers library builds

* Listeners library builds

* View models build

* Views now build

* Added documentation comments

* Started removing binding dependencies from views

* Removed fragment imports used only for comments in order to build view files

* Pulled binding dependenvy out of ConceptCardViewModel

* Edited R import statements for Bazel to build

* Fixed more errors, view_model builds

* Worked through more errors

* Added a dependency

* View library builds

* Ordered BUILD file for better merging

* Both databinding adapters and recyclerview adapters are building

* Starting writing databinding resources library

* Removed unused listeners

* Added missing comments

* Formatted files and added missing @nonnull annotations

* Fixed ktlint errors

* Revert "Formatted files and added missing @nonnull annotations"

This reverts commit 84b6125.

* Added genrule for viewmodel files

* Added view genrule

* Both Bazel and Gradle are building

* Fixed ktlint errors

* Delete vcs.xml

* Renamed files, deleted unused files, and added some documentation

* Improved implementation of some functions in ViewBindingShimImpl and added documentation

* Fixed ktlint errors

* Put genrules in a loop, created issue to remove genrules post-gradle and added TODO

* Added more documentation, created an issue to remove shim files, added TODO

* Fixed Gradle build error

* Added documentation, created an issue, added a TODO

* Formatted single line comments

* Fixing more nits

* Fixed more nits.

* Fixed getTimeAgo() function

* Suppressed warning in bindToRecyclerViewAdapter

* Builds in both Bazel and Gradle

* Added comments to BUILD file

* Fixed profile_chooser_profile_view error

* Fixed profile_chooser_add_view

* Fixed walthrough_final_fragment error

* Fixed profile_chooser_fragment error

* Fixed walthrough_activity error

* Fixed onboarding_fragment error

* Fixed audio_fragment error

* Fixed unused presnter errors, databining resources now build

* Builds with Gradle

* Fixed WalkthroughWelcomeFragmentPresenter to not contain unnecessary methods bc of interface

* Removed unnecessary method from WalkthroughActivity

* Removed the need for ProfileChooserListener, added comments to WalkthroughListeners

* Genrule is working

* Simplified genrule

* Alphabetized lists in app module BUILD

* Quick cleanup, added missing documentation

* App library is building with Bazel

* Added Retrofit+Gson dependency for NetworkModule to build with Gradle

* Binary builds

* Started debugging runtime errors

* Fixed domain BUILD

* Added genrule comments, simplified gnerule targets in lists

* Fixed QuestionPlayerFragmentPresenter and StateFragmentPresenter

* Fixed QuestionPlayerViewModel & FRagmentPresenter as well as StateViewModel & FragmentPresenter

* Fixed some nits

* Fixed ktlint errors

* Added assets

* First test builds and passes

* Fixed DragDrop ViewBinding implementations, added modules to TestComponent

* Fix ktlint errors

* Fixed nits in TextViewBA

* Fixed Audio + Language test appearance bug

* Fixed ktlint errors

* Fixed ktlint error in FAQSingleActivityPresenter

* Fixed ktlin errors

* Cleaned up app BUILD file a bit

* Testing module tests now pass, all domain tests pass except StateRetreiver

* Removed unused dependencies, aplhabetized dependencies

* Fixed list formation

* Cleaned up BUILD

* Fixed nits

* Fixing some nits

* Refactored file names

* Altered walkthrough welcome fragment

* Renamed wasProfileEverBeenAddedValue to hasProfileEverBeenAddedValue

* Fixed ktlint error

* Removed unused dependencies and alphabetized them

* Deleted unused methods in ImageViewBA

* Removed data attribute from domain library

* Excluded DataBinderMapperImpl from Gradle build

* Most tests build and pass

* Started getting sharedTests to run

* All tests now build

* Fixed ktlint errors

* Fixed ktlint error

* Added missing TODOs

* Fixed merge errors

* Fixed nits

* Removed unnecessary field in StateFragmentAccessibilityTest

* Fixed StateFragmentAccessibilityTestFixed StateFragmentAccessibilityTestFixed StateFragmentAccessibilityTestFixed StateFragmentAccessibilityTestFixed StateFragmentAccessibilityTestFixed StateFragmentAccessibilityTestFixed StateFragmentAccessibilityTestFixed StateFragmentAccessibilityTestFixed StateFragmentAccessibilityTest

* Injected context in AppVersionViewModel

* Used lambda function to resolve issues with QuestionPlayerVM and QuestionPlayerFragmentPresenter

* Fixed small errors

* Fixed ktlint errors

* Removed Moshi dependency from NetworkModule

* Fixed ktlint error

* Fixing listener file naming

* Fixed NetworkModule issue by removing it from ApplicationComponent temporarily

* Restored NetworkModule, fixed some nits

* Fixed typo, deleted unused file, removed retrofit gradle dependencies

* Removed NetworkModule from test files, fixed nits, fixed enable_data_binding in oppia_android_test

* Fixing nits

* Fixed more nits

* Fixed StateFragmentPresenter and view model, fixed some nits

* Fixed ktlint errors

* Altered for loop to append directly to DATABINDING_ADAPTERS

* Created issue and added TODO for ApplicationComponent and NetworkModule

* Added TODOs to test files with NetworkModule removed, added documentation to DataBinderMapperImple, fixed nits

* Added documentations, fixed nits

* Fixed nits

* Fixed ktlint error

* Added documentation, fixed nits

* Added a few nits

* Removed unused imports

* Fixed nits

* Created issue, added TODO, updated docs

* Starting to put genrules into a macro

* Fixed documentation

* Added comment about binding adapters in Java

* Created test_with_resources and applied it to tests

* Fixed nits, created a PackageManagerHelper file

* Fixed nits

* Update app/src/main/java/org/oppia/app/utility/PackageManagerHelper.kt

Co-authored-by: Ben Henning <[email protected]>

* Fixed inject issue and nits

* Fixed typo

* Changed filename, included new file in Annotations library

* Fixed lint error

* Added bazel_build_app task to main.yml

* Test out GITHUB_WORKSPACE and HOME

* Using env PATH variables

* Added $GITHUB_WORKSPACE to android_tools command

* Fixed typo in build command

* Change from my repo to oppia's bazel repo

Co-authored-by: Ben Henning <[email protected]>

* Change Setup to Set up

Co-authored-by: Ben Henning <[email protected]>

* Collapse creating tmp/android_tools into extract android_tools

Co-authored-by: Ben Henning <[email protected]>

* Changed apk path to be absolute

* Made cp use absolute path

* Updated cp command

* Update main.yml

* Update main.yml

Co-authored-by: Ben Henning <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants