Skip to content

Commit

Permalink
Fixes part of #59: Add Bazel + Robolectric testing support for Utilit…
Browse files Browse the repository at this point in the history
…y module [BLOCKED: #1488] (#1495)

* Working on having one module build with bazel

* Created initial app-level WORKSPACE file

* Added proto_library rule to build model app module

* Added newline at end of WORKSPACE file

* Created macro to process proto files

* Both Bazel and Gradle now build /model successfully

* Fixed typo in BUILD

* Added missing end of file empty lines

* Added Robolectric dependencies and general build rule

* Source files building in both systems - added a TODO for test files

* Turned two kt_android_library rules into one

* Added dependencies for test files

* Created kt_android_library rule for source files

* Add TODO for android_local_test rule

* Added a test manifest for android_local_test()

* Added Firebase dependencies and git_repository for tools_android

* Refactored google-services.json, imported new dependencies

* Fixed Bens nits

* Fixed space in WORKSPACE comment

* Got a demo test working in both Java and Kotlin

* Added rules_java dependencies for protocol buffers

* Added java_proto_library rules, each proto file now has its own rule

* Remove unnecessary srcs attribute for android_library

* Rename bzl file macro

* Added Robolectric dependencies and general build rule

* Source files building in both systems - added a TODO for test files

* Turned two kt_android_library rules into one

* Added dependencies for test files

* Created kt_android_library rule for source files

* Add TODO for android_local_test rule

* Changed model visability, added model and util dependencies to testing

* Added dependencies to testing_main_lib

* Testing source files now build

* Test files are building

* Changed to java_lite

* Added EOF newlines

* Each library now has its own build rule

* Utility is now one rule

* Changed visibility for utility_lib

* Added duplicate google-services.json file to please Gradle

* Utility tests are building and passing (except in_memory_blocking_cache_test)

* Added android_local_test() rules for testing, building but not passing

* Added a test manifest for testing module

* Oppia_android_test is working

* Utility_test is now working

* Testing_test.bzl is now working

* changed all android_local_test rules to utility_test rules

* Named test rules correctly

* Added missing dependency, all tests now pass

* Removed all unused dependencies

* Changed event_logger.proto to oppia_logger.proto

* Added missing EOF newlines

* Fixed visibility

* Remove addressed TODOs

* Fixed bug in import statements for exploration.proto, topic.proto, and question.proto

* Deleted DemoJava

* CHanged rules_kotlin version

* Added Firebase dependencies

* Removed AsyncResultTest example

* Removed AsynchResultTest example

* Firebase dependencies added

* Removed unnecessary comments in WORKSPACE and moved rules_kotlin

* Added re-naming TODOs

* Renamed java_proto rules java_proto_lite

* Added doc comments to model/BUILD.bazel and format_import_proto_library

* Added comments to WORKSPACE file

* Fixed nits

* Added comment to kt_android_library() rule

* Fixed more nits

* Added Firebase comment

* Fixed merge conflicts and nits

* Deleted unused dependencies from testing_main_lib

* Fixed nits and error with testing lib dependencies

* Changed library name to model

* Formatted WORKSPACE comment

* Formatted TODO statement

* Changed format_import_proto_library comment

* Added EOF newline

* Created Issue and linked TODO in WORKSPACE

* Edited model BUILD file top comment

* Addressed nits

* Fixed nits and added comments

* Fixing nits

* Deleted unnecessary dependencies and testing example file

* Fixed manifest issues

* Move google json file

* Restore app version of json

* Edit TODO

* Deleted TODO

* Changed Firebase comment

* Added testing functionality from later PR

* Added comments to bzl files

* Added targetSDK to manifests

* Changed crashlytics_lib to crashlytics

* Changed testing_tests visibility

* Added comment to utility_test.bzl

* Changed type of comment ticks

* Fixed typos and all tests pass

* Removed empty line

* Fixed nits and added TODOs

* Added Args to document comment

* Changed targetSDK to 29

* Formatted TODO

* Added root BUILD file

* Moved google-services.json

* Added gogle-services.json back to app

* Trying to remove combined testing library

* Changed targetSDK to 29

* Tests pass now with deps passed in.

* Created TEST_DEPS list to avoid duplicate list of dependencies

* Removed unused resources and manifest

* Updated comments to reflect changes

* Changed deps to be a parameter, changed targetSDK back to 28 because tests do not pass at 29

* Fixed indentation in utility/BUILD

* Updated comment for utility_test.bzl

* Updated comment for testing_test

* Formatted dependencies and removed unused dependency

* Updated dependency list

* Header for oppia_android_test now fits on one line

* Edited documentation for oppia_android_test

* Updated documentation for utility and testing BUILD files

* Changed src to srcs

* Changed src to srcs

* Fixed the duplicate google-services.json issue

* Created Issue and added TODO

* Added minSDK back

* Alphabetized dependencies

* Fixed firebase target

* Changed targetSdk to 28
  • Loading branch information
miaboloix authored Aug 9, 2020
1 parent 681616a commit 892a0c3
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 5 deletions.
1 change: 1 addition & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# TODO(#1532): Rename file to 'BUILD' post-Gradle.
77 changes: 72 additions & 5 deletions utility/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ This library contains utilities that all other modules, minus model, depend on.
load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_android_library")
load("@rules_jvm_external//:defs.bzl", "artifact")
load("@dagger//:workspace_defs.bzl", "dagger_rules")
load("//:oppia_android_test.bzl", "oppia_android_test")
load("//utility:utility_test.bzl", "utility_test")

# Library for general-purpose utilities.
kt_android_library(
Expand All @@ -27,10 +29,75 @@ kt_android_library(
visibility = ["//visibility:public"],
)

# TODO(#59): Write a kt_android_library() rule to build test files and an android_local_test() rule.
'''
Because test files depend on the testing module source files being built, these rules have been left
for a later PR.
'''
TEST_DEPS = [
":utility",
":dagger",
"//testing",
"//model",
"//app:crashlytics",
"//app:crashlytics_deps",
"@robolectric//bazel:android-all",
artifact("org.jetbrains.kotlin:kotlin-reflect"),
artifact("com.google.truth:truth"),
artifact("androidx.test.ext:junit"),
artifact("org.jetbrains.kotlin:kotlin-test-junit"),
artifact("org.mockito:mockito-core"),
]

utility_test(
name = "AsyncResultTest",
srcs = ["src/test/java/org/oppia/util/data/AsyncResultTest.kt"],
test_class = "org.oppia.util.data.AsyncResultTest",
deps = TEST_DEPS,
)

utility_test(
name = "DataProvidersTest",
srcs = ["src/test/java/org/oppia/util/data/DataProvidersTest.kt"],
test_class = "org.oppia.util.data.DataProvidersTest",
deps = TEST_DEPS,
)

utility_test(
name = "InMemoryBlockingCacheTest",
srcs = ["src/test/java/org/oppia/util/data/InMemoryBlockingCacheTest.kt"],
test_class = "org.oppia.util.data.InMemoryBlockingCacheTest",
deps = TEST_DEPS,
)

utility_test(
name = "DateTimeUtilTest",
srcs = ["src/test/java/org/oppia/util/datetime/DateTimeUtilTest.kt"],
test_class = "org.oppia.util.datetime.DateTimeUtilTest",
deps = TEST_DEPS,
)

utility_test(
name = "EventBundleCreatorTest",
srcs = ["src/test/java/org/oppia/util/logging/EventBundleCreatorTest.kt"],
test_class = "org.oppia.util.logging.EventBundleCreatorTest",
deps = TEST_DEPS,
)

utility_test(
name = "NetworkConnectionUtilTest",
srcs = ["src/test/java/org/oppia/util/networking/NetworkConnectionUtilTest.kt"],
test_class = "org.oppia.util.networking.NetworkConnectionUtilTest",
deps = TEST_DEPS,
)

utility_test(
name = "DirectoryManagementUtilTest",
srcs = ["src/test/java/org/oppia/util/profile/DirectoryManagementUtilTest.kt"],
test_class = "org.oppia.util.profile.DirectoryManagementUtilTest",
deps = TEST_DEPS,
)

utility_test(
name = "OppiaDateTimeFormatterTest",
srcs = ["src/test/java/org/oppia/util/system/OppiaDateTimeFormatterTest.kt"],
test_class = "org.oppia.util.system.OppiaDateTimeFormatterTest",
deps = TEST_DEPS,
)

dagger_rules()
22 changes: 22 additions & 0 deletions utility/utility_test.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
load("//:oppia_android_test.bzl", "oppia_android_test")

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.
'''

oppia_android_test(
name = name,
srcs = srcs,
custom_package = "org.oppia.util",
test_class = test_class,
test_manifest = "src/test/AndroidManifest.xml",
deps = deps,
)

0 comments on commit 892a0c3

Please sign in to comment.