diff --git a/BUILD.bazel b/BUILD.bazel new file mode 100644 index 00000000000..e69de29bb2d diff --git a/WORKSPACE b/WORKSPACE index b63c57dc6a4..3d6b42663bc 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -108,32 +108,34 @@ load("@rules_jvm_external//:defs.bzl", "maven_install") maven_install( artifacts = DAGGER_ARTIFACTS + [ - "org.robolectric:robolectric:4.3", - "org.robolectric:annotations:4.3", + "androidx.annotation:annotation:1.1.0", "androidx.appcompat:appcompat:1.0.2", "androidx.core:core-ktx:1.0.1", "androidx.lifecycle:lifecycle-livedata-ktx:2.2.0-alpha03", "androidx.test.ext:junit:1.1.1", "com.android.support:support-annotations:28.0.0", - "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.2", - "org.jetbrains.kotlinx:kotlinx-coroutines-test:1.2.2", - "org.jetbrains.kotlin:kotlin-stdlib-jdk7:jar:1.3.72", - "org.jetbrains.kotlin:kotlin-test-junit:1.3.72", - "com.google.truth:truth:0.43", + "com.caverock:androidsvg-aar:1.4", + "com.crashlytics.sdk.android:crashlytics:2.9.8", + "com.github.bumptech.glide:glide:4.11.0", "com.google.firebase:firebase-analytics:17.4.4", "com.google.firebase:firebase-crashlytics:17.1.1", - "com.crashlytics.sdk.android:crashlytics:2.9.8", + "com.google.truth:truth:0.43", "io.fabric.sdk.android:fabric:1.4.7", - "com.github.bumptech.glide:glide:4.11.0", - "com.caverock:androidsvg-aar:1.4", - "org.mockito:mockito-core:2.19.0", "junit:junit:4.12", + "org.jetbrains.kotlin:kotlin-reflect:1.3.41", + "org.jetbrains.kotlin:kotlin-stdlib-jdk7:jar:1.3.72", + "org.jetbrains.kotlin:kotlin-test-junit:1.3.72", + "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.2", + "org.jetbrains.kotlinx:kotlinx-coroutines-test:1.2.2", + "org.mockito:mockito-core:2.19.0", + "org.robolectric:annotations:4.3", + "org.robolectric:robolectric:4.3", ], repositories = DAGGER_REPOSITORIES + [ - "https://maven.google.com", - "https://repo1.maven.org/maven2", - "https://jcenter.bintray.com/", "https://bintray.com/bintray/jcenter", + "https://jcenter.bintray.com/", "https://maven.fabric.io/public", + "https://maven.google.com", + "https://repo1.maven.org/maven2", ], ) diff --git a/oppia_android_test.bzl b/oppia_android_test.bzl new file mode 100644 index 00000000000..b65be3406e1 --- /dev/null +++ b/oppia_android_test.bzl @@ -0,0 +1,33 @@ +load("@rules_jvm_external//:defs.bzl", "artifact") +load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_android_library") + +def oppia_android_test(name, srcs, test_manifest, custom_package, test_class, deps): + ''' + 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". + deps: list of str. The list of dependencies needed to run the tests. + ''' + + kt_android_library( + name = name + "_lib", + custom_package = custom_package, + srcs = srcs, + deps = deps, + testonly = True, + ) + + native.android_local_test( + name = name, + custom_package = custom_package, + test_class = test_class, + manifest = test_manifest, + deps = [ ":" + name + "_lib",] + deps, + ) diff --git a/testing/BUILD.bazel b/testing/BUILD.bazel new file mode 100644 index 00000000000..c226c15fc6b --- /dev/null +++ b/testing/BUILD.bazel @@ -0,0 +1,50 @@ +# TODO(#1532): Rename file to 'BUILD' post-Gradle. +''' +This library contains fake objects used for testing as well as tests for these objects. +''' + +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("//testing:testing_test.bzl", "testing_test") + +# Library for general-purpose testing fakes. +kt_android_library( + name = "testing", + custom_package = "org.oppia.testing", + srcs = glob(["src/main/java/org/oppia/testing/*.kt"]), + manifest = "src/main/AndroidManifest.xml", + deps = [ + ":dagger", + "//utility", + artifact("org.jetbrains.kotlinx:kotlinx-coroutines-test"), + artifact("org.robolectric:robolectric"), + ], + visibility = ["//visibility:public"], + ) + +TEST_DEPS = [ + ":testing", + ":dagger", + "@robolectric//bazel:android-all", + artifact("org.jetbrains.kotlin:kotlin-reflect"), + artifact("com.google.truth:truth"), + artifact("androidx.test.ext:junit"), +] + +testing_test( + name = "FakeEventLoggerTest", + srcs = ["src/test/java/org/oppia/testing/FakeEventLoggerTest.kt"], + test_class = "org.oppia.testing.FakeEventLoggerTest", + deps = TEST_DEPS, +) + +testing_test( + name = "FakeExceptionLoggerTest", + srcs = ["src/test/java/org/oppia/testing/FakeExceptionLoggerTest.kt"], + test_class = "org.oppia.testing.FakeExceptionLoggerTest", + deps = TEST_DEPS, +) + +dagger_rules() diff --git a/testing/src/test/AndroidManifest.xml b/testing/src/test/AndroidManifest.xml new file mode 100644 index 00000000000..866b17b8a84 --- /dev/null +++ b/testing/src/test/AndroidManifest.xml @@ -0,0 +1,5 @@ + + + diff --git a/testing/testing_test.bzl b/testing/testing_test.bzl new file mode 100644 index 00000000000..fd3532adcb5 --- /dev/null +++ b/testing/testing_test.bzl @@ -0,0 +1,22 @@ +load("//:oppia_android_test.bzl", "oppia_android_test") + +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. + ''' + + oppia_android_test( + name = name, + srcs = srcs, + custom_package = "org.oppia.testing", + test_class = test_class, + test_manifest = "src/test/AndroidManifest.xml", + deps = deps, + ) diff --git a/utility/BUILD.bazel b/utility/BUILD.bazel index b511f7fc1de..71b1be94cef 100644 --- a/utility/BUILD.bazel +++ b/utility/BUILD.bazel @@ -1,10 +1,6 @@ # TODO(#1532): Rename file to 'BUILD' post-Gradle. ''' This library contains utilities that all other modules, minus model, depend on. -It also contains Robolectric and JUnit tests for it's utilities. -In Bazel, Kotlin source files are built into a library using the kt_android_library() rule. -Kotlin test files must be built in their own kt_android_library() rule and added as a dependency to -an android_local_test() rule which configures instrumentation tests in Bazel. ''' load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_android_library")