-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reorganize test rules under
//rules
package. Add compose unit test …
- Loading branch information
1 parent
5d70380
commit dcbf0cf
Showing
42 changed files
with
176 additions
and
192 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
load("@grab_bazel_common//tools/android_mock:andorid_mock.bzl", "mock_android_jar") | ||
|
||
mock_android_jar() |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
load("@grab_bazel_common//rules/test:test.bzl", "gen_test_targets") | ||
load("@grab_bazel_common//rules/android:runtime_resources.bzl", "runtime_resources") | ||
|
||
def android_unit_test( | ||
name, | ||
deps, | ||
srcs, | ||
additional_src_sets = [], | ||
associates = [], | ||
resources = [], | ||
enable_compose = False, | ||
**kwargs): | ||
"""A macro that executes all android library unit tests. | ||
Usage: | ||
The macro creates a single build target to compile all Android unit test classes and then loads | ||
all Test class onto a test suite for execution. | ||
The macro adds a mocked Android jar to compile classpath similar to Android Gradle Plugin's | ||
testOptions.unitTests.returnDefaultValues = true feature. | ||
The macro assumes Kotlin is used and will use rules_kotlin's kt_jvm_test for execution with | ||
mocked android.jar on the classpath. | ||
Executing via Robolectric is currently not supported. | ||
Args: | ||
name: name for the test target, | ||
srcs: the test sources under test. | ||
src_sets: The root source set path of all test sources | ||
deps: the build dependencies to use for the generated the android local test target | ||
and all valid arguments that you want to pass to the android_local_test target | ||
associates: associates target to allow access to internal members from the main Kotlin target | ||
resources: A list of files that should be include in a Java jar. | ||
enable_compose: Enable Jetpack Compose compiler on Kotlin sources | ||
""" | ||
|
||
runtime_resources_name = name + "-runtime-resources" | ||
runtime_resources( | ||
name = runtime_resources_name, | ||
deps = deps, | ||
) | ||
|
||
if enable_compose: | ||
deps.extend(["@grab_bazel_common//rules/android/compose:compose-plugin"]) | ||
|
||
gen_test_targets( | ||
name = name, | ||
srcs = srcs, | ||
additional_src_sets = additional_src_sets, | ||
associates = associates, | ||
deps = deps, | ||
test_compile_deps = [ | ||
"@grab_bazel_common//rules/android:mock_android_jar", | ||
], | ||
test_runtime_deps = [ | ||
":" + runtime_resources_name, | ||
"@grab_bazel_common//rules/android:mock_android_jar", | ||
"@com_github_jetbrains_kotlin//:kotlin-reflect", | ||
], | ||
resources = resources, | ||
**kwargs | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,21 @@ | ||
load("@grab_bazel_common//rules/android:android_binary.bzl", _android_binary = "android_binary") | ||
load("@grab_bazel_common//rules/android:android_library.bzl", _android_library = "android_library") | ||
load("@grab_bazel_common//rules/android:android_instrumentation.bzl", _android_instrumentation_binary = "android_instrumentation_binary") | ||
load("@grab_bazel_common//rules/android:test.bzl", _android_unit_test = "android_unit_test") | ||
load( | ||
"@grab_bazel_common//rules/kotlin:kotlin.bzl", | ||
_kt_compiler_plugin = "kt_compiler_plugin", | ||
_kt_jvm_library = "kt_jvm_library", | ||
) | ||
load("@grab_bazel_common//rules/kotlin:test.bzl", _kotlin_test = "kotlin_test") | ||
|
||
# Android | ||
android_binary = _android_binary | ||
android_library = _android_library | ||
android_instrumentation_binary = _android_instrumentation_binary | ||
android_unit_test = _android_unit_test | ||
|
||
# Kotlin | ||
kt_jvm_library = _kt_jvm_library | ||
kt_compiler_plugin = _kt_compiler_plugin | ||
kotlin_test = _kotlin_test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
load("@grab_bazel_common//rules/test:test.bzl", "gen_test_targets") | ||
|
||
def kotlin_test( | ||
name, | ||
srcs, | ||
deps, | ||
additional_src_sets = [], | ||
associates = [], | ||
**kwargs): | ||
"""A macro that generates test targets to execute all Kotlin unit tests. | ||
Usage: | ||
The macro creates a single build target to compile all unit test classes and then creates a test target containing each Test class. | ||
The name of the test target is derived from test class name and location of the file on disk. | ||
Args: | ||
name: name for the test target, | ||
srcs: the test sources under test. | ||
src_sets: The root source set path of all test sources | ||
deps: the build dependencies to use for the generated the android local test target | ||
and all valid arguments that you want to pass to the android_local_test target | ||
associates: associates target to allow access to internal members from the main Kotlin target | ||
""" | ||
gen_test_targets( | ||
name = name, | ||
srcs = srcs, | ||
additional_src_sets = additional_src_sets, | ||
associates = associates, | ||
deps = deps, | ||
test_compile_deps = [], | ||
test_runtime_deps = [ | ||
"@com_github_jetbrains_kotlin//:kotlin-reflect", | ||
], | ||
**kwargs | ||
) |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.