Skip to content

Commit 603013c

Browse files
authored
Merge pull request #458 from rechsteiner/ui-tests
Setup basic UI tests
2 parents 8083728 + ca17943 commit 603013c

File tree

6 files changed

+209
-4
lines changed

6 files changed

+209
-4
lines changed

.circleci/config.yml

+7-3
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@ version: 2
22
jobs:
33
build-and-test:
44
macos:
5-
xcode: "11.1.0"
5+
xcode: "11.3.0"
66
steps:
77
- checkout
88
- run:
9-
name: Run Tests
10-
command: xcodebuild -project Parchment.xcodeproj -scheme "Parchment" -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 11,OS=13.1' test
9+
name: Run Unit Tests
10+
command: xcodebuild -project Parchment.xcodeproj -scheme "Parchment" -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 11,OS=13.3' test
11+
- run:
12+
name: Run UI Tests
13+
command: xcodebuild -project Parchment.xcodeproj -scheme "ParchmentUITests" -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 11,OS=13.3' test
14+
1115

1216
workflows:
1317
version: 2

Example/ExamplesViewController.swift

+9
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,18 @@ enum Example: CaseIterable {
4444
final class ExamplesViewController: UITableViewController {
4545
static let CellIdentifier = "CellIdentifier"
4646

47+
var isUITesting: Bool {
48+
return ProcessInfo.processInfo.arguments.contains("--ui-testing")
49+
}
50+
4751
override func viewDidLoad() {
4852
super.viewDidLoad()
4953
tableView.register(UITableViewCell.self, forCellReuseIdentifier: Self.CellIdentifier)
54+
55+
if isUITesting {
56+
let viewController = createViewController(for: .basic)
57+
navigationController?.setViewControllers([viewController], animated: false)
58+
}
5059
}
5160

5261
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

Parchment.xcodeproj/project.pbxproj

+134-1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
95A84B0520E586FA0031520F /* PagingStaticDataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95A84B0420E586FA0031520F /* PagingStaticDataSource.swift */; };
8989
95A84B0D20ED46920031520F /* AnyPagingItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95A84B0C20ED46920031520F /* AnyPagingItem.swift */; };
9090
95B301171E59FCD500B95D02 /* UIEdgeInsets.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95B301161E59FCD500B95D02 /* UIEdgeInsets.swift */; };
91+
95D2AE44242BC1FA00AC3D46 /* ParchmentUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95D2AE43242BC1FA00AC3D46 /* ParchmentUITests.swift */; };
9192
95D78FDB2287138F00E6EE7C /* MockCollectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95D78FDA2287138F00E6EE7C /* MockCollectionView.swift */; };
9293
95D78FDD228713B800E6EE7C /* MockCollectionViewLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95D78FDC228713B800E6EE7C /* MockCollectionViewLayout.swift */; };
9394
95D78FDF228715C800E6EE7C /* MockPagingControllerDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95D78FDE228715C800E6EE7C /* MockPagingControllerDelegate.swift */; };
@@ -127,6 +128,13 @@
127128
remoteGlobalIDString = 3EA04A591C53BFF40054E5E0;
128129
remoteInfo = Example;
129130
};
131+
95D2AE46242BC1FA00AC3D46 /* PBXContainerItemProxy */ = {
132+
isa = PBXContainerItemProxy;
133+
containerPortal = 3EA04A421C53BFE40054E5E0 /* Project object */;
134+
proxyType = 1;
135+
remoteGlobalIDString = 3EA04A591C53BFF40054E5E0;
136+
remoteInfo = Example;
137+
};
130138
/* End PBXContainerItemProxy section */
131139

132140
/* Begin PBXCopyFilesBuildPhase section */
@@ -228,6 +236,9 @@
228236
95A84B0420E586FA0031520F /* PagingStaticDataSource.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PagingStaticDataSource.swift; sourceTree = "<group>"; };
229237
95A84B0C20ED46920031520F /* AnyPagingItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnyPagingItem.swift; sourceTree = "<group>"; };
230238
95B301161E59FCD500B95D02 /* UIEdgeInsets.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UIEdgeInsets.swift; sourceTree = "<group>"; };
239+
95D2AE41242BC1F900AC3D46 /* ParchmentUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = ParchmentUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
240+
95D2AE43242BC1FA00AC3D46 /* ParchmentUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ParchmentUITests.swift; sourceTree = "<group>"; };
241+
95D2AE45242BC1FA00AC3D46 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
231242
95D78FDA2287138F00E6EE7C /* MockCollectionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockCollectionView.swift; sourceTree = "<group>"; };
232243
95D78FDC228713B800E6EE7C /* MockCollectionViewLayout.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockCollectionViewLayout.swift; sourceTree = "<group>"; };
233244
95D78FDE228715C800E6EE7C /* MockPagingControllerDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockPagingControllerDelegate.swift; sourceTree = "<group>"; };
@@ -269,6 +280,13 @@
269280
);
270281
runOnlyForDeploymentPostprocessing = 0;
271282
};
283+
95D2AE3E242BC1F900AC3D46 /* Frameworks */ = {
284+
isa = PBXFrameworksBuildPhase;
285+
buildActionMask = 2147483647;
286+
files = (
287+
);
288+
runOnlyForDeploymentPostprocessing = 0;
289+
};
272290
/* End PBXFrameworksBuildPhase section */
273291

274292
/* Begin PBXGroup section */
@@ -353,6 +371,7 @@
353371
children = (
354372
3EA04A4D1C53BFE40054E5E0 /* Parchment */,
355373
3E504EC51C7465B000AE1CE3 /* ParchmentTests */,
374+
95D2AE42242BC1FA00AC3D46 /* ParchmentUITests */,
356375
3EA04A5B1C53BFF40054E5E0 /* Example */,
357376
3EA04A4C1C53BFE40054E5E0 /* Products */,
358377
);
@@ -364,6 +383,7 @@
364383
3EA04A4B1C53BFE40054E5E0 /* Parchment.framework */,
365384
3EA04A5A1C53BFF40054E5E0 /* Example.app */,
366385
3E504EC41C7465B000AE1CE3 /* ParchmentTests.xctest */,
386+
95D2AE41242BC1F900AC3D46 /* ParchmentUITests.xctest */,
367387
);
368388
name = Products;
369389
sourceTree = "<group>";
@@ -548,6 +568,15 @@
548568
path = Storyboard;
549569
sourceTree = "<group>";
550570
};
571+
95D2AE42242BC1FA00AC3D46 /* ParchmentUITests */ = {
572+
isa = PBXGroup;
573+
children = (
574+
95D2AE43242BC1FA00AC3D46 /* ParchmentUITests.swift */,
575+
95D2AE45242BC1FA00AC3D46 /* Info.plist */,
576+
);
577+
path = ParchmentUITests;
578+
sourceTree = "<group>";
579+
};
551580
95D78FE5228728FD00E6EE7C /* Mocks */ = {
552581
isa = PBXGroup;
553582
children = (
@@ -631,13 +660,31 @@
631660
productReference = 3EA04A5A1C53BFF40054E5E0 /* Example.app */;
632661
productType = "com.apple.product-type.application";
633662
};
663+
95D2AE40242BC1F900AC3D46 /* ParchmentUITests */ = {
664+
isa = PBXNativeTarget;
665+
buildConfigurationList = 95D2AE4A242BC1FA00AC3D46 /* Build configuration list for PBXNativeTarget "ParchmentUITests" */;
666+
buildPhases = (
667+
95D2AE3D242BC1F900AC3D46 /* Sources */,
668+
95D2AE3E242BC1F900AC3D46 /* Frameworks */,
669+
95D2AE3F242BC1F900AC3D46 /* Resources */,
670+
);
671+
buildRules = (
672+
);
673+
dependencies = (
674+
95D2AE47242BC1FA00AC3D46 /* PBXTargetDependency */,
675+
);
676+
name = ParchmentUITests;
677+
productName = ParchmentUITests;
678+
productReference = 95D2AE41242BC1F900AC3D46 /* ParchmentUITests.xctest */;
679+
productType = "com.apple.product-type.bundle.ui-testing";
680+
};
634681
/* End PBXNativeTarget section */
635682

636683
/* Begin PBXProject section */
637684
3EA04A421C53BFE40054E5E0 /* Project object */ = {
638685
isa = PBXProject;
639686
attributes = {
640-
LastSwiftUpdateCheck = 1100;
687+
LastSwiftUpdateCheck = 1130;
641688
LastUpgradeCheck = 1110;
642689
ORGANIZATIONNAME = "Martin Rechsteiner";
643690
TargetAttributes = {
@@ -656,6 +703,12 @@
656703
DevelopmentTeam = G4TGN24VA2;
657704
LastSwiftMigration = 1020;
658705
};
706+
95D2AE40242BC1F900AC3D46 = {
707+
CreatedOnToolsVersion = 11.3.1;
708+
DevelopmentTeam = G4TGN24VA2;
709+
ProvisioningStyle = Automatic;
710+
TestTargetID = 3EA04A591C53BFF40054E5E0;
711+
};
659712
};
660713
};
661714
buildConfigurationList = 3EA04A451C53BFE40054E5E0 /* Build configuration list for PBXProject "Parchment" */;
@@ -674,6 +727,7 @@
674727
3EA04A4A1C53BFE40054E5E0 /* Parchment */,
675728
3E504EC31C7465B000AE1CE3 /* ParchmentTests */,
676729
3EA04A591C53BFF40054E5E0 /* Example */,
730+
95D2AE40242BC1F900AC3D46 /* ParchmentUITests */,
677731
);
678732
};
679733
/* End PBXProject section */
@@ -703,6 +757,13 @@
703757
);
704758
runOnlyForDeploymentPostprocessing = 0;
705759
};
760+
95D2AE3F242BC1F900AC3D46 /* Resources */ = {
761+
isa = PBXResourcesBuildPhase;
762+
buildActionMask = 2147483647;
763+
files = (
764+
);
765+
runOnlyForDeploymentPostprocessing = 0;
766+
};
706767
/* End PBXResourcesBuildPhase section */
707768

708769
/* Begin PBXSourcesBuildPhase section */
@@ -816,6 +877,14 @@
816877
);
817878
runOnlyForDeploymentPostprocessing = 0;
818879
};
880+
95D2AE3D242BC1F900AC3D46 /* Sources */ = {
881+
isa = PBXSourcesBuildPhase;
882+
buildActionMask = 2147483647;
883+
files = (
884+
95D2AE44242BC1FA00AC3D46 /* ParchmentUITests.swift in Sources */,
885+
);
886+
runOnlyForDeploymentPostprocessing = 0;
887+
};
819888
/* End PBXSourcesBuildPhase section */
820889

821890
/* Begin PBXTargetDependency section */
@@ -834,6 +903,11 @@
834903
target = 3EA04A591C53BFF40054E5E0 /* Example */;
835904
targetProxy = 95CCFF331CF1CDD700233464 /* PBXContainerItemProxy */;
836905
};
906+
95D2AE47242BC1FA00AC3D46 /* PBXTargetDependency */ = {
907+
isa = PBXTargetDependency;
908+
target = 3EA04A591C53BFF40054E5E0 /* Example */;
909+
targetProxy = 95D2AE46242BC1FA00AC3D46 /* PBXContainerItemProxy */;
910+
};
837911
/* End PBXTargetDependency section */
838912

839913
/* Begin PBXVariantGroup section */
@@ -1087,6 +1161,56 @@
10871161
};
10881162
name = Release;
10891163
};
1164+
95D2AE48242BC1FA00AC3D46 /* Debug */ = {
1165+
isa = XCBuildConfiguration;
1166+
buildSettings = {
1167+
CLANG_ANALYZER_NONNULL = YES;
1168+
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
1169+
CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
1170+
CLANG_ENABLE_OBJC_WEAK = YES;
1171+
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
1172+
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
1173+
CODE_SIGN_STYLE = Automatic;
1174+
DEVELOPMENT_TEAM = G4TGN24VA2;
1175+
GCC_C_LANGUAGE_STANDARD = gnu11;
1176+
INFOPLIST_FILE = ParchmentUITests/Info.plist;
1177+
IPHONEOS_DEPLOYMENT_TARGET = 13.2;
1178+
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
1179+
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
1180+
MTL_FAST_MATH = YES;
1181+
PRODUCT_BUNDLE_IDENTIFIER = com.martinrechsteiner.ParchmentUITests;
1182+
PRODUCT_NAME = "$(TARGET_NAME)";
1183+
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
1184+
SWIFT_VERSION = 5.0;
1185+
TARGETED_DEVICE_FAMILY = "1,2";
1186+
TEST_TARGET_NAME = Example;
1187+
};
1188+
name = Debug;
1189+
};
1190+
95D2AE49242BC1FA00AC3D46 /* Release */ = {
1191+
isa = XCBuildConfiguration;
1192+
buildSettings = {
1193+
CLANG_ANALYZER_NONNULL = YES;
1194+
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
1195+
CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
1196+
CLANG_ENABLE_OBJC_WEAK = YES;
1197+
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
1198+
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
1199+
CODE_SIGN_STYLE = Automatic;
1200+
DEVELOPMENT_TEAM = G4TGN24VA2;
1201+
GCC_C_LANGUAGE_STANDARD = gnu11;
1202+
INFOPLIST_FILE = ParchmentUITests/Info.plist;
1203+
IPHONEOS_DEPLOYMENT_TARGET = 13.2;
1204+
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
1205+
MTL_FAST_MATH = YES;
1206+
PRODUCT_BUNDLE_IDENTIFIER = com.martinrechsteiner.ParchmentUITests;
1207+
PRODUCT_NAME = "$(TARGET_NAME)";
1208+
SWIFT_VERSION = 5.0;
1209+
TARGETED_DEVICE_FAMILY = "1,2";
1210+
TEST_TARGET_NAME = Example;
1211+
};
1212+
name = Release;
1213+
};
10901214
/* End XCBuildConfiguration section */
10911215

10921216
/* Begin XCConfigurationList section */
@@ -1126,6 +1250,15 @@
11261250
defaultConfigurationIsVisible = 0;
11271251
defaultConfigurationName = Release;
11281252
};
1253+
95D2AE4A242BC1FA00AC3D46 /* Build configuration list for PBXNativeTarget "ParchmentUITests" */ = {
1254+
isa = XCConfigurationList;
1255+
buildConfigurations = (
1256+
95D2AE48242BC1FA00AC3D46 /* Debug */,
1257+
95D2AE49242BC1FA00AC3D46 /* Release */,
1258+
);
1259+
defaultConfigurationIsVisible = 0;
1260+
defaultConfigurationName = Release;
1261+
};
11291262
/* End XCConfigurationList section */
11301263
};
11311264
rootObject = 3EA04A421C53BFE40054E5E0 /* Project object */;

Parchment/Classes/PagingTitleCell.swift

+1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ open class PagingTitleCell: PagingCell {
6464
}
6565

6666
open func configureAccessibility() {
67+
accessibilityIdentifier = viewModel?.title
6768
contentView.accessibilityLabel = viewModel?.title
6869
contentView.accessibilityTraits = viewModel?.selected ?? false ? .selected : .none
6970
}

ParchmentUITests/Info.plist

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>CFBundleDevelopmentRegion</key>
6+
<string>$(DEVELOPMENT_LANGUAGE)</string>
7+
<key>CFBundleExecutable</key>
8+
<string>$(EXECUTABLE_NAME)</string>
9+
<key>CFBundleIdentifier</key>
10+
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
11+
<key>CFBundleInfoDictionaryVersion</key>
12+
<string>6.0</string>
13+
<key>CFBundleName</key>
14+
<string>$(PRODUCT_NAME)</string>
15+
<key>CFBundlePackageType</key>
16+
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
17+
<key>CFBundleShortVersionString</key>
18+
<string>1.0</string>
19+
<key>CFBundleVersion</key>
20+
<string>1</string>
21+
</dict>
22+
</plist>
+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import XCTest
2+
3+
final class ParchmentUITests: XCTestCase {
4+
var app: XCUIApplication!
5+
6+
override func setUp() {
7+
continueAfterFailure = false
8+
app = XCUIApplication()
9+
app.launchArguments = ["--ui-testing"]
10+
app.launch()
11+
}
12+
13+
func testSelect() {
14+
let cell0 = app.collectionViews.cells["View 0"]
15+
let cell1 = app.collectionViews.cells["View 1"]
16+
17+
cell1.tap()
18+
let content1 = app.scrollViews.firstMatch.staticTexts["1"]
19+
XCTAssertTrue(content1.waitForExistence(timeout: 1))
20+
XCTAssertTrue(cell1.isSelected)
21+
22+
cell0.tap()
23+
let content0 = app.scrollViews.firstMatch.staticTexts["0"]
24+
XCTAssertTrue(content0.waitForExistence(timeout: 1))
25+
XCTAssertTrue(cell0.isSelected)
26+
}
27+
28+
func testSwipe() {
29+
app.scrollViews.firstMatch.swipeLeft()
30+
let content1 = app.scrollViews.firstMatch.staticTexts["1"]
31+
XCTAssertTrue(content1.waitForExistence(timeout: 1))
32+
33+
let cell1 = app.collectionViews.cells["View 1"]
34+
XCTAssertTrue(cell1.isSelected)
35+
}
36+
}

0 commit comments

Comments
 (0)