我一直在尝试通过 google test lib 添加 cpp 测试并通过 ios_unit_test 目标运行它们。由于某种原因,测试根本没有执行。我试图将 cpp 测试库 di 集成到...
我一直在尝试通过 google test lib 添加 cpp 测试并通过 ios_unit_test 目标运行它们。由于某种原因,测试根本没有执行。我尝试直接或通过 objc_library 集成 cpp 测试库,但所有方法都不起作用。这是设置。
模块.bzl
module(
name = "bazelsample",
version = "0.0.1",
repo_name = "bazel_sample"
)
bazel_dep(name = "apple_support", version = "1.15.1")
bazel_dep(name = "rules_apple", version = "3.5.1", repo_name="build_bazel_rules_apple")
bazel_dep(name = "rules_ios", version = "4.4.0", repo_name="build_bazel_rules_ios")
bazel_dep(name = "googletest", version = "1.14.0")
建造
load("@build_bazel_rules_apple//apple:ios.bzl", "ios_unit_test")
load("@rules_cc//cc:defs.bzl", "cc_library")
cc_library(
name = "cpp_tests_lib",
srcs = [
"cpp_tests_lib/cpp_test.cpp",
],
deps = [
"@googletest//:gtest",
"@googletest//:gtest_main",
],
visibility = ["//visibility:public"],
)
objc_library(
name = "objc_tests_lib",
srcs = [
"objc_tests_lib/GoogleTests.mm",
],
deps = [
":cpp_tests_lib",
"@googletest//:gtest",
"@googletest//:gtest_main",
],
visibility = ["//visibility:public"],
sdk_frameworks = ["XCTest"],
)
objc_library(
name = "objc_cpp_tests_lib",
srcs = [
"cpp_tests_lib/cpp_test.cpp",
"objc_tests_lib/GoogleTests.mm",
],
deps = [
"@googletest//:gtest",
"@googletest//:gtest_main",
],
visibility = ["//visibility:public"],
sdk_frameworks = ["XCTest"],
)
ios_unit_test(
name = "ios_cpp_tests_lib",
minimum_os_version = "17.0",
deps = [":cpp_tests_lib"],
visibility = ["//visibility:public"],
)
ios_unit_test(
name = "ios_objc_tests_lib",
minimum_os_version = "17.0",
deps = [":objc_tests_lib"],
visibility = ["//visibility:public"],
)
ios_unit_test(
name = "ios_objc_cpp_tests_lib",
minimum_os_version = "17.0",
deps = [":objc_cpp_tests_lib"],
visibility = ["//visibility:public"],
)
这是 cpp 测试类
cpp_测试.cpp
#include <gtest/gtest.h>
TEST(YourTestSuite, YourTestCase) {
EXPECT_EQ(2 + 2, 4);
}
TEST(YourTestSuite, YourTestCaseTwo) {
EXPECT_EQ(2 + 2, 4);
}
我在运行时使用该 GoogleTests.mm
文件 的链接 .
cpp 测试在运行时不会加载到 google 测试库中,并且我还通过静态方法确认,除非从 objc 测试类调用,否则 cpp 测试类代码在运行时根本不会执行。
这是示例项目 https://github.com/prasadpamidi/Bazel-iOS-Cpp-Sample
我是否遗漏了某些内容,或者无法通过 ios_unit_test 规则集成和运行 cpp 测试?
感谢任何帮助。