Skip to content

Commit

Permalink
Adding some unit tests for bundle sorting/packing feature
Browse files Browse the repository at this point in the history
  • Loading branch information
ravimandala committed Jul 29, 2019
1 parent 099be41 commit 44e683d
Show file tree
Hide file tree
Showing 7 changed files with 337 additions and 21 deletions.
4 changes: 4 additions & 0 deletions BPSampleApp/BPSampleApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
BAB24F4C1DB5D45E00867756 /* BPSampleAppTests.m in Sources */ = {isa = PBXBuildFile; fileRef = BAB24F4B1DB5D45E00867756 /* BPSampleAppTests.m */; };
BAB24F5D1DB5D83C00867756 /* BPAppNegativeTests.m in Sources */ = {isa = PBXBuildFile; fileRef = BAB24F5C1DB5D83C00867756 /* BPAppNegativeTests.m */; };
BAFCCA601E36DC2000E33C31 /* BPSampleAppUITests.m in Sources */ = {isa = PBXBuildFile; fileRef = BAFCCA5F1E36DC2000E33C31 /* BPSampleAppUITests.m */; };
E492360122EF61F300395D98 /* BPSampleAppMoarTests.m in Sources */ = {isa = PBXBuildFile; fileRef = E492360022EF61F300395D98 /* BPSampleAppMoarTests.m */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -101,6 +102,7 @@
BAFCCA5D1E36DC2000E33C31 /* BPSampleAppUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = BPSampleAppUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
BAFCCA5F1E36DC2000E33C31 /* BPSampleAppUITests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = BPSampleAppUITests.m; sourceTree = "<group>"; };
BAFCCA611E36DC2000E33C31 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
E492360022EF61F300395D98 /* BPSampleAppMoarTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = BPSampleAppMoarTests.m; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -240,6 +242,7 @@
BAB24F4A1DB5D45E00867756 /* BPSampleAppTests */ = {
isa = PBXGroup;
children = (
E492360022EF61F300395D98 /* BPSampleAppMoarTests.m */,
BAB24F4B1DB5D45E00867756 /* BPSampleAppTests.m */,
BAB24F4D1DB5D45E00867756 /* Info.plist */,
32FEEBBC2012B93D005916EF /* BPSampleAppSwiftTests.swift */,
Expand Down Expand Up @@ -567,6 +570,7 @@
buildActionMask = 2147483647;
files = (
BAB24F4C1DB5D45E00867756 /* BPSampleAppTests.m in Sources */,
E492360122EF61F300395D98 /* BPSampleAppMoarTests.m in Sources */,
32FEEBBD2012B93D005916EF /* BPSampleAppSwiftTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
35 changes: 35 additions & 0 deletions BPSampleApp/BPSampleAppTests/BPSampleAppMoarTests.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// BPSampleAppMoarTests.m
// BPSampleAppTests
//
// Created by Ravi K. Mandala on 7/29/19.
// Copyright © 2019 LinkedIn. All rights reserved.
//

#import <XCTest/XCTest.h>

@interface BPSampleAppMoarTests : XCTestCase

@end


@implementation BPSampleAppMoarTests

- (void)setUp {
[super setUp];
// Put setup code here. This method is called before the invocation of each test method in the class.

}

- (void)tearDown {
// Put teardown code here. This method is called after the invocation of each test method in the class.
[super tearDown];
}

- (void)testCase000 { XCTAssert(YES);}
- (void)testCase001 { XCTAssert(YES);}
- (void)testCase002 { XCTAssert(YES);}
- (void)testCase003 { XCTAssert(YES);}
- (void)testCase004 { XCTAssert(YES);}

@end
3 changes: 3 additions & 0 deletions Bluepill-cli/BPInstanceTests/BPTestHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@
// Return path to the sample video file.
+ (NSString *)sampleVideoPath;

// Return path to the sample times json file.
+ (NSString *)sampleTimesJsonPath;

// Return the sample photo path.
+ (NSString *)samplePhotoPath;

Expand Down
4 changes: 4 additions & 0 deletions Bluepill-cli/BPInstanceTests/BPTestHelper.m
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ + (NSString *)sampleVideoPath {
return [[[NSBundle bundleForClass:[self class]] resourcePath] stringByAppendingPathComponent:@"demo.mov"];
}

+ (NSString *)sampleTimesJsonPath {
return [[[NSBundle bundleForClass:[self class]] resourcePath] stringByAppendingPathComponent:@"times.json"];
}

+ (NSString *)samplePhotoPath {
return [[[NSBundle bundleForClass:[self class]] resourcePath] stringByAppendingPathComponent:@"image.png"];
}
Expand Down
86 changes: 65 additions & 21 deletions Bluepill-runner/BluepillRunnerTests/BPPackerTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,51 @@ - (void)testPackingProvidesBalancedBundles {
}
}

- (void)testSmartPackIfJsonFound {
self.config.testTimeEstimatesJsonFile = [BPTestHelper sampleTimesJsonPath];
self.config.testBundlePath = [BPTestHelper sampleAppBalancingTestsBundlePath];
self.config.testCasesToSkip = @[@"BPSampleAppTests/testCase000"];
self.config.numSims = @8;
BPApp *app = [BPApp appWithConfig:self.config withError:nil];
XCTAssert(app != nil);
NSArray<BPXCTestFile *> *bundles;
NSError *error;
bundles = [BPPacker packTests:app.testBundles configuration:self.config andError:&error];
XCTAssert(error == nil);
XCTAssert([app.testBundles count] == [bundles count]);
}

- (void)testSmartPackIfJsonMissing {
self.config.testTimeEstimatesJsonFile = @"invalid/times/file/path.json";
self.config.testBundlePath = [BPTestHelper sampleAppBalancingTestsBundlePath];
self.config.testCasesToSkip = @[@"BPSampleAppTests/testCase000"];
self.config.numSims = @8;
BPApp *app = [BPApp appWithConfig:self.config withError:nil];
XCTAssert(app != nil);
NSArray<BPXCTestFile *> *bundles;
NSError *error;
bundles = [BPPacker packTests:app.testBundles configuration:self.config andError:&error];
XCTAssert(error != nil);
XCTAssert([bundles count] == 0);
}

- (void)testSortByTimeEstimates {
self.config.testTimeEstimatesJsonFile = [BPTestHelper sampleTimesJsonPath];
self.config.testBundlePath = nil;
BPApp *app = [BPApp appWithConfig:self.config withError:nil];
XCTAssert(app != nil);
XCTAssert([app.testBundles count] == 5);
// Make sure we don't split when we don't want to
self.config.numSims = @4;
NSArray<BPXCTestFile *> *bundles = [BPPacker packTests:app.testBundles configuration:self.config andError:nil];
XCTAssert([bundles count] == [app.testBundles count]);
XCTAssert([[[bundles objectAtIndex:0] name] isEqualToString:@"BPSampleAppTests"]);
XCTAssert([[[bundles objectAtIndex:1] name] isEqualToString:@"BPSampleAppHangingTests"]);
XCTAssert([[[bundles objectAtIndex:2] name] isEqualToString:@"BPSampleAppCrashingTests"]);
XCTAssert([[[bundles objectAtIndex:3] name] isEqualToString:@"BPAppNegativeTests"]);
XCTAssert([[[bundles objectAtIndex:4] name] isEqualToString:@"BPSampleAppFatalErrorTests"]);
}

- (void)testPacking {
NSArray *want, *got;
NSArray *allTests;
Expand Down Expand Up @@ -139,10 +184,10 @@ - (void)testPacking {
XCTAssertEqual([bundles[1].skipTestIdentifiers count], 0);
XCTAssertEqual([bundles[2].skipTestIdentifiers count], 0);
XCTAssertEqual([bundles[3].skipTestIdentifiers count], 0);
XCTAssertEqual([bundles[4].skipTestIdentifiers count], 149);
XCTAssertEqual([bundles[5].skipTestIdentifiers count], 149);
XCTAssertEqual([bundles[6].skipTestIdentifiers count], 149);
XCTAssertEqual([bundles[7].skipTestIdentifiers count], 159);
XCTAssertEqual([bundles[4].skipTestIdentifiers count], 152);
XCTAssertEqual([bundles[5].skipTestIdentifiers count], 152);
XCTAssertEqual([bundles[6].skipTestIdentifiers count], 152);
XCTAssertEqual([bundles[7].skipTestIdentifiers count], 165);

self.config.numSims = @1;
bundles = [BPPacker packTests:app.testBundles configuration:self.config andError:nil];
Expand All @@ -156,21 +201,21 @@ - (void)testPacking {
XCTAssertEqual([bundles[1].skipTestIdentifiers count], 0);
XCTAssertEqual([bundles[2].skipTestIdentifiers count], 0);
XCTAssertEqual([bundles[3].skipTestIdentifiers count], 0);
XCTAssertEqual([bundles[4].skipTestIdentifiers count], 189);
XCTAssertEqual([bundles[5].skipTestIdentifiers count], 189);
XCTAssertEqual([bundles[6].skipTestIdentifiers count], 189);
XCTAssertEqual([bundles[7].skipTestIdentifiers count], 189);
XCTAssertEqual([bundles[8].skipTestIdentifiers count], 189);
XCTAssertEqual([bundles[9].skipTestIdentifiers count], 189);
XCTAssertEqual([bundles[10].skipTestIdentifiers count], 189);
XCTAssertEqual([bundles[11].skipTestIdentifiers count], 189);
XCTAssertEqual([bundles[12].skipTestIdentifiers count], 189);
XCTAssertEqual([bundles[13].skipTestIdentifiers count], 189);
XCTAssertEqual([bundles[14].skipTestIdentifiers count], 189);
XCTAssertEqual([bundles[15].skipTestIdentifiers count], 189);
XCTAssertEqual([bundles[16].skipTestIdentifiers count], 189);
XCTAssertEqual([bundles[17].skipTestIdentifiers count], 189);
XCTAssertEqual([bundles[18].skipTestIdentifiers count], 189);
XCTAssertEqual([bundles[4].skipTestIdentifiers count], 194);
XCTAssertEqual([bundles[5].skipTestIdentifiers count], 194);
XCTAssertEqual([bundles[6].skipTestIdentifiers count], 194);
XCTAssertEqual([bundles[7].skipTestIdentifiers count], 194);
XCTAssertEqual([bundles[8].skipTestIdentifiers count], 194);
XCTAssertEqual([bundles[9].skipTestIdentifiers count], 194);
XCTAssertEqual([bundles[10].skipTestIdentifiers count], 194);
XCTAssertEqual([bundles[11].skipTestIdentifiers count], 194);
XCTAssertEqual([bundles[12].skipTestIdentifiers count], 194);
XCTAssertEqual([bundles[13].skipTestIdentifiers count], 194);
XCTAssertEqual([bundles[14].skipTestIdentifiers count], 194);
XCTAssertEqual([bundles[15].skipTestIdentifiers count], 194);
XCTAssertEqual([bundles[16].skipTestIdentifiers count], 194);
XCTAssertEqual([bundles[17].skipTestIdentifiers count], 194);
XCTAssertEqual([bundles[18].skipTestIdentifiers count], 194);
XCTAssertEqual([bundles[19].skipTestIdentifiers count], 195);

NSMutableArray *toRun = [[NSMutableArray alloc] init];
Expand All @@ -183,7 +228,7 @@ - (void)testPacking {

XCTAssertEqual(bundles.count, 4);
for (BPXCTestFile *bundle in bundles) {
XCTAssertEqual(bundle.skipTestIdentifiers.count, 197);
XCTAssertEqual(bundle.skipTestIdentifiers.count, 202);
}
}

Expand All @@ -198,7 +243,6 @@ - (void)testPackingWithTestsToSkip {
for (BPXCTestFile *bundle in bundles) {
XCTAssertTrue([bundle.skipTestIdentifiers containsObject:@"BPSampleAppTests/testCase000"], @"testCase000 should be in testToSkip for all bundles");
}

}

@end
Loading

0 comments on commit 44e683d

Please sign in to comment.