Skip to content

Commit cab51d4

Browse files
authored
Turn on ABT unit tests with SPM (#6016)
1 parent 8211bec commit cab51d4

File tree

2 files changed

+21
-18
lines changed

2 files changed

+21
-18
lines changed

FirebaseABTesting/Tests/Unit/Utilities/ABTTestUtilities.m

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,17 @@
2020

2121
@implementation ABTTestUtilities
2222

23+
+ (NSBundle *)getBundle {
24+
#if SWIFT_PACKAGE
25+
return Firebase_ABTestingUnit_SWIFTPM_MODULE_BUNDLE();
26+
#else
27+
return [NSBundle bundleForClass:[ABTTestUtilities class]];
28+
#endif
29+
}
30+
2331
+ (ABTExperimentPayload *)payloadFromTestFilename:(NSString *)filename {
24-
NSString *testJsonDataFilePath =
25-
[[NSBundle bundleForClass:[ABTTestUtilities class]] pathForResource:filename ofType:@"txt"];
32+
NSBundle *abtBundle = [self getBundle];
33+
NSString *testJsonDataFilePath = [abtBundle pathForResource:filename ofType:@"txt"];
2634
NSError *readTextError = nil;
2735
NSString *fileText = [[NSString alloc] initWithContentsOfFile:testJsonDataFilePath
2836
encoding:NSUTF8StringEncoding
@@ -36,8 +44,8 @@ + (ABTExperimentPayload *)payloadFromTestFilename:(NSString *)filename {
3644

3745
+ (NSData *)payloadJSONDataFromFile:(NSString *)filename
3846
modifiedStartTime:(nullable NSDate *)modifiedStartTime {
39-
NSString *testJsonDataFilePath =
40-
[[NSBundle bundleForClass:[ABTTestUtilities class]] pathForResource:filename ofType:@"txt"];
47+
NSBundle *abtBundle = [self getBundle];
48+
NSString *testJsonDataFilePath = [abtBundle pathForResource:filename ofType:@"txt"];
4149
NSError *readTextError = nil;
4250
NSString *fileText = [[NSString alloc] initWithContentsOfFile:testJsonDataFilePath
4351
encoding:NSUTF8StringEncoding

Package.swift

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -275,20 +275,15 @@ let package = Package(
275275
.define("FIRABTesting_VERSION", to: "0.0.1"), // TODO: Fix version
276276
]
277277
),
278-
// Disabled. Pending resolution of accessing SPM resources from Objective C.
279-
// See https://forums.swift.org/t/finding-swift-package-manager-resources/38058
280-
// .testTarget(
281-
// name: "ABTestingUnit",
282-
// dependencies: ["FirebaseABTesting", "OCMock"],
283-
// path: "FirebaseABTesting/Tests/Unit",
284-
// resources: [.process("Resources")],
285-
//// resources: [
286-
////
287-
//// "Resources/TestABTPayload1.txt"],
288-
// cSettings: [
289-
// .headerSearchPath("../../.."),
290-
// ]
291-
// ),
278+
.testTarget(
279+
name: "ABTestingUnit",
280+
dependencies: ["FirebaseABTesting", "OCMock"],
281+
path: "FirebaseABTesting/Tests/Unit",
282+
resources: [.process("Resources")],
283+
cSettings: [
284+
.headerSearchPath("../../.."),
285+
]
286+
),
292287
.target(
293288
name: "FirebaseAuth",
294289
dependencies: ["FirebaseCore",

0 commit comments

Comments
 (0)