Skip to content

Commit

Permalink
POC of generating screenshots with a Unit Test
Browse files Browse the repository at this point in the history
It uses my personal library that I open sourced just now. Still early in the work, but improving…
Screenshots are generated in a folder aside UT, and can be moved around in a fastlane script that execute those tests.
  • Loading branch information
Dean151 committed Nov 17, 2023
1 parent 0582d6d commit 9c28c7f
Show file tree
Hide file tree
Showing 7 changed files with 290 additions and 2 deletions.
25 changes: 25 additions & 0 deletions Basic-Car-Maintenance-ScreenshotsTests/ScreenshotsTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// ScreenshotsTests.swift
// Basic-Car-Maintenance-ScreenshotsTests
//
// Created by Thomas Durand on 11/17/2023.
//

import XCTest

@testable import Basic_Car_Maintenance
import ScreenshotKit

final class ScreenshotsTests: XCTestCase {
@MainActor
func testMainScreenScreenshot() throws {
generateScreenshots(for: {
MainTabView()
.environment(ActionService.shared)
.withSystemDecoration()
},
named: "MainScreen",
type: .device(.iPhone(orientations: .portrait)),
prefix: "BasicCarMaintenance")
}
}
151 changes: 151 additions & 0 deletions Basic-Car-Maintenance.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
E58499662ACDDA8B00634660 /* ContributorsListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E58499652ACDDA8B00634660 /* ContributorsListView.swift */; };
E58499682ACDDA9A00634660 /* ContributorsProfileView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E58499672ACDDA9A00634660 /* ContributorsProfileView.swift */; };
E584996A2ACDDAFF00634660 /* Contributor.swift in Sources */ = {isa = PBXBuildFile; fileRef = E58499692ACDDAFF00634660 /* Contributor.swift */; };
E99CF7492B07C66D0053C4DB /* ScreenshotsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E99CF7482B07C66D0053C4DB /* ScreenshotsTests.swift */; };
E99CF7502B07C8B10053C4DB /* ScreenshotKit in Frameworks */ = {isa = PBXBuildFile; productRef = E99CF74F2B07C8B10053C4DB /* ScreenshotKit */; };
FF09FC912AB6FF44006BE61A /* AuthenticationView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FF09FC902AB6FF44006BE61A /* AuthenticationView.swift */; };
FF218EF62B00865F0025A533 /* AnalyticsService.swift in Sources */ = {isa = PBXBuildFile; fileRef = FF218EF52B00865F0025A533 /* AnalyticsService.swift */; };
FF3DDF522AA4D28F009D91C4 /* DashboardViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = FF3DDF512AA4D28F009D91C4 /* DashboardViewModel.swift */; };
Expand Down Expand Up @@ -65,6 +67,13 @@
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
E99CF74A2B07C66D0053C4DB /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = FF5D139B2A86C2D500BC9BD6 /* Project object */;
proxyType = 1;
remoteGlobalIDString = FF5D13A22A86C2D600BC9BD6;
remoteInfo = "Basic-Car-Maintenance";
};
FF5D13B52A86C2D800BC9BD6 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = FF5D139B2A86C2D500BC9BD6 /* Project object */;
Expand Down Expand Up @@ -123,6 +132,11 @@
E58499652ACDDA8B00634660 /* ContributorsListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContributorsListView.swift; sourceTree = "<group>"; };
E58499672ACDDA9A00634660 /* ContributorsProfileView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContributorsProfileView.swift; sourceTree = "<group>"; };
E58499692ACDDAFF00634660 /* Contributor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Contributor.swift; sourceTree = "<group>"; };
E99CF7412B07C6150053C4DB /* ScreenshotTests.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = ScreenshotTests.xcconfig; sourceTree = "<group>"; };
E99CF7462B07C66D0053C4DB /* Basic-Car-Maintenance-ScreenshotsTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "Basic-Car-Maintenance-ScreenshotsTests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
E99CF7482B07C66D0053C4DB /* ScreenshotsTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScreenshotsTests.swift; sourceTree = "<group>"; };
E99CF7512B07C9000053C4DB /* Screenshots.xctestplan */ = {isa = PBXFileReference; lastKnownFileType = text; path = Screenshots.xctestplan; sourceTree = "<group>"; };
E99CF7522B07C9160053C4DB /* Tests.xctestplan */ = {isa = PBXFileReference; lastKnownFileType = text; path = Tests.xctestplan; sourceTree = "<group>"; };
FF0813562AD0A83000910EFA /* UITests.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = UITests.xcconfig; sourceTree = "<group>"; };
FF0813572AD0A92700910EFA /* Widget.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Widget.xcconfig; sourceTree = "<group>"; };
FF098EFA2AB3424E003EC0FE /* Basic-Car-Maintenance.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = "Basic-Car-Maintenance.xcconfig"; sourceTree = SOURCE_ROOT; };
Expand Down Expand Up @@ -164,6 +178,14 @@
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
E99CF7432B07C66D0053C4DB /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
E99CF7502B07C8B10053C4DB /* ScreenshotKit in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
FF5D13A02A86C2D600BC9BD6 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
Expand Down Expand Up @@ -273,6 +295,14 @@
path = ViewModels;
sourceTree = "<group>";
};
E99CF7472B07C66D0053C4DB /* Basic-Car-Maintenance-ScreenshotsTests */ = {
isa = PBXGroup;
children = (
E99CF7482B07C66D0053C4DB /* ScreenshotsTests.swift */,
);
path = "Basic-Car-Maintenance-ScreenshotsTests";
sourceTree = "<group>";
};
FF3DDF492AA4386C009D91C4 /* Views */ = {
isa = PBXGroup;
children = (
Expand All @@ -296,10 +326,13 @@
children = (
FFBE79BA2AD0A48C0005524E /* Configurations */,
FF098EFA2AB3424E003EC0FE /* Basic-Car-Maintenance.xcconfig */,
E99CF7512B07C9000053C4DB /* Screenshots.xctestplan */,
E99CF7522B07C9160053C4DB /* Tests.xctestplan */,
FF5D13A52A86C2D600BC9BD6 /* Basic-Car-Maintenance */,
FFDADF822ACD35A100DDEF79 /* Basic-Car-Maintenance-Widget */,
FF5D13B72A86C2D800BC9BD6 /* Basic-Car-Maintenance-Tests */,
FF5D13C12A86C2D800BC9BD6 /* Basic-Car-Maintenance-UITests */,
E99CF7472B07C66D0053C4DB /* Basic-Car-Maintenance-ScreenshotsTests */,
FF5D13A42A86C2D600BC9BD6 /* Products */,
FFC8CDB12AA4226900D129A6 /* Frameworks */,
);
Expand All @@ -312,6 +345,7 @@
FF5D13B42A86C2D800BC9BD6 /* Basic-Car-Maintenance-Tests.xctest */,
FF5D13BE2A86C2D800BC9BD6 /* Basic-Car-Maintenance-UITests.xctest */,
FFDADF7D2ACD35A100DDEF79 /* Basic-Car-Maintenance-WidgetExtension.appex */,
E99CF7462B07C66D0053C4DB /* Basic-Car-Maintenance-ScreenshotsTests.xctest */,
);
name = Products;
sourceTree = "<group>";
Expand Down Expand Up @@ -404,6 +438,7 @@
children = (
FFDADF5D2ACCE9AB00DDEF79 /* Project.xcconfig */,
FFBE79BB2AD0A57D0005524E /* UnitTests.xcconfig */,
E99CF7412B07C6150053C4DB /* ScreenshotTests.xcconfig */,
FF0813562AD0A83000910EFA /* UITests.xcconfig */,
FF0813572AD0A92700910EFA /* Widget.xcconfig */,
);
Expand Down Expand Up @@ -481,6 +516,27 @@
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
E99CF7452B07C66D0053C4DB /* Basic-Car-Maintenance-ScreenshotsTests */ = {
isa = PBXNativeTarget;
buildConfigurationList = E99CF74C2B07C66D0053C4DB /* Build configuration list for PBXNativeTarget "Basic-Car-Maintenance-ScreenshotsTests" */;
buildPhases = (
E99CF7422B07C66D0053C4DB /* Sources */,
E99CF7432B07C66D0053C4DB /* Frameworks */,
E99CF7442B07C66D0053C4DB /* Resources */,
);
buildRules = (
);
dependencies = (
E99CF74B2B07C66D0053C4DB /* PBXTargetDependency */,
);
name = "Basic-Car-Maintenance-ScreenshotsTests";
packageProductDependencies = (
E99CF74F2B07C8B10053C4DB /* ScreenshotKit */,
);
productName = "Basic-Car-MaintenanceTests.ScreenshotsTests";
productReference = E99CF7462B07C66D0053C4DB /* Basic-Car-Maintenance-ScreenshotsTests.xctest */;
productType = "com.apple.product-type.bundle.unit-test";
};
FF5D13A22A86C2D600BC9BD6 /* Basic-Car-Maintenance */ = {
isa = PBXNativeTarget;
buildConfigurationList = FF5D13C82A86C2D800BC9BD6 /* Build configuration list for PBXNativeTarget "Basic-Car-Maintenance" */;
Expand Down Expand Up @@ -574,6 +630,10 @@
LastSwiftUpdateCheck = 1500;
LastUpgradeCheck = 1500;
TargetAttributes = {
E99CF7452B07C66D0053C4DB = {
CreatedOnToolsVersion = 15.0.1;
TestTargetID = FF5D13A22A86C2D600BC9BD6;
};
FF5D13A22A86C2D600BC9BD6 = {
CreatedOnToolsVersion = 15.0;
};
Expand Down Expand Up @@ -611,20 +671,29 @@
mainGroup = FF5D139A2A86C2D500BC9BD6;
packageReferences = (
FFC8CDA52AA3867A00D129A6 /* XCRemoteSwiftPackageReference "firebase-ios-sdk" */,
E99CF7402B07C58A0053C4DB /* XCRemoteSwiftPackageReference "ScreenshotKit" */,
);
productRefGroup = FF5D13A42A86C2D600BC9BD6 /* Products */;
projectDirPath = "";
projectRoot = "";
targets = (
FF5D13A22A86C2D600BC9BD6 /* Basic-Car-Maintenance */,
FF5D13B32A86C2D800BC9BD6 /* Basic-Car-Maintenance-Tests */,
E99CF7452B07C66D0053C4DB /* Basic-Car-Maintenance-ScreenshotsTests */,
FF5D13BD2A86C2D800BC9BD6 /* Basic-Car-Maintenance-UITests */,
FFDADF7C2ACD35A100DDEF79 /* Basic-Car-Maintenance-WidgetExtension */,
);
};
/* End PBXProject section */

/* Begin PBXResourcesBuildPhase section */
E99CF7442B07C66D0053C4DB /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
FF5D13A12A86C2D600BC9BD6 /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
Expand Down Expand Up @@ -683,6 +752,14 @@
/* End PBXShellScriptBuildPhase section */

/* Begin PBXSourcesBuildPhase section */
E99CF7422B07C66D0053C4DB /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
E99CF7492B07C66D0053C4DB /* ScreenshotsTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
FF5D139F2A86C2D600BC9BD6 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
Expand Down Expand Up @@ -752,6 +829,11 @@
/* End PBXSourcesBuildPhase section */

/* Begin PBXTargetDependency section */
E99CF74B2B07C66D0053C4DB /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
target = FF5D13A22A86C2D600BC9BD6 /* Basic-Car-Maintenance */;
targetProxy = E99CF74A2B07C66D0053C4DB /* PBXContainerItemProxy */;
};
FF5D13B62A86C2D800BC9BD6 /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
target = FF5D13A22A86C2D600BC9BD6 /* Basic-Car-Maintenance */;
Expand All @@ -770,6 +852,53 @@
/* End PBXTargetDependency section */

/* Begin XCBuildConfiguration section */
E99CF74D2B07C66D0053C4DB /* Debug */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = E99CF7412B07C6150053C4DB /* ScreenshotTests.xcconfig */;
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
ENABLE_USER_SCRIPT_SANDBOXING = YES;
GENERATE_INFOPLIST_FILE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 17.0;
MARKETING_VERSION = 1.0;
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = iphoneos;
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator";
SUPPORTS_MACCATALYST = NO;
SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO;
SWIFT_EMIT_LOC_STRINGS = NO;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Basic-Car-Maintenance.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/Basic-Car-Maintenance";
};
name = Debug;
};
E99CF74E2B07C66D0053C4DB /* Release */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = E99CF7412B07C6150053C4DB /* ScreenshotTests.xcconfig */;
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
ENABLE_USER_SCRIPT_SANDBOXING = YES;
GENERATE_INFOPLIST_FILE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 17.0;
MARKETING_VERSION = 1.0;
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = iphoneos;
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator";
SUPPORTS_MACCATALYST = NO;
SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO;
SWIFT_EMIT_LOC_STRINGS = NO;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Basic-Car-Maintenance.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/Basic-Car-Maintenance";
VALIDATE_PRODUCT = YES;
};
name = Release;
};
FF5D13C62A86C2D800BC9BD6 /* Debug */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = FFDADF5D2ACCE9AB00DDEF79 /* Project.xcconfig */;
Expand Down Expand Up @@ -1102,6 +1231,15 @@
/* End XCBuildConfiguration section */

/* Begin XCConfigurationList section */
E99CF74C2B07C66D0053C4DB /* Build configuration list for PBXNativeTarget "Basic-Car-Maintenance-ScreenshotsTests" */ = {
isa = XCConfigurationList;
buildConfigurations = (
E99CF74D2B07C66D0053C4DB /* Debug */,
E99CF74E2B07C66D0053C4DB /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
FF5D139E2A86C2D500BC9BD6 /* Build configuration list for PBXProject "Basic-Car-Maintenance" */ = {
isa = XCConfigurationList;
buildConfigurations = (
Expand Down Expand Up @@ -1150,6 +1288,14 @@
/* End XCConfigurationList section */

/* Begin XCRemoteSwiftPackageReference section */
E99CF7402B07C58A0053C4DB /* XCRemoteSwiftPackageReference "ScreenshotKit" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/Dean151/ScreenshotKit";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 0.0.1;
};
};
FFC8CDA52AA3867A00D129A6 /* XCRemoteSwiftPackageReference "firebase-ios-sdk" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/firebase/firebase-ios-sdk.git";
Expand All @@ -1161,6 +1307,11 @@
/* End XCRemoteSwiftPackageReference section */

/* Begin XCSwiftPackageProductDependency section */
E99CF74F2B07C8B10053C4DB /* ScreenshotKit */ = {
isa = XCSwiftPackageProductDependency;
package = E99CF7402B07C58A0053C4DB /* XCRemoteSwiftPackageReference "ScreenshotKit" */;
productName = ScreenshotKit;
};
FF4E82BD2AD39863004949AF /* FirebaseRemoteConfig */ = {
isa = XCSwiftPackageProductDependency;
package = FFC8CDA52AA3867A00D129A6 /* XCRemoteSwiftPackageReference "firebase-ios-sdk" */;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,15 @@
"version" : "2.3.1"
}
},
{
"identity" : "screenshotkit",
"kind" : "remoteSourceControl",
"location" : "https://github.com/Dean151/ScreenshotKit",
"state" : {
"revision" : "ce37bc243497fab768ee0686aa2df66084727821",
"version" : "0.0.1"
}
},
{
"identity" : "swift-protobuf",
"kind" : "remoteSourceControl",
Expand All @@ -107,6 +116,24 @@
"revision" : "3c54ab05249f59f2c6641dd2920b8358ea9ed127",
"version" : "1.24.0"
}
},
{
"identity" : "swift-snapshot-testing",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-snapshot-testing.git",
"state" : {
"revision" : "4862d48562483d274a2ac7522d905c9237a31a48",
"version" : "1.15.0"
}
},
{
"identity" : "swift-syntax",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-syntax.git",
"state" : {
"revision" : "6ad4ea24b01559dde0773e3d091f1b9e36175036",
"version" : "509.0.2"
}
}
],
"version" : 2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,16 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
shouldAutocreateTestPlan = "YES">
shouldUseLaunchSchemeArgsEnv = "YES">
<TestPlans>
<TestPlanReference
reference = "container:Screenshots.xctestplan">
</TestPlanReference>
<TestPlanReference
reference = "container:Tests.xctestplan"
default = "YES">
</TestPlanReference>
</TestPlans>
<Testables>
<TestableReference
skipped = "NO"
Expand All @@ -51,6 +59,17 @@
ReferencedContainer = "container:Basic-Car-Maintenance.xcodeproj">
</BuildableReference>
</TestableReference>
<TestableReference
skipped = "NO"
parallelizable = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "E99CF7452B07C66D0053C4DB"
BuildableName = "Basic-Car-Maintenance-ScreenshotsTests.xctest"
BlueprintName = "Basic-Car-Maintenance-ScreenshotsTests"
ReferencedContainer = "container:Basic-Car-Maintenance.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
</TestAction>
<LaunchAction
Expand Down
Loading

0 comments on commit 9c28c7f

Please sign in to comment.