diff --git a/GlobalTestHelpers/Support/BitwardenTestCase.swift b/GlobalTestHelpers/Support/BitwardenTestCase.swift index 7db932186..28c538ceb 100644 --- a/GlobalTestHelpers/Support/BitwardenTestCase.swift +++ b/GlobalTestHelpers/Support/BitwardenTestCase.swift @@ -9,7 +9,9 @@ open class BitwardenTestCase: XCTestCase { @MainActor override open class func setUp() { - if UIDevice.current.name != "iPhone 16 Pro" || UIDevice.current.systemVersion != "18.1" { + let shouldSkipSimulatorCheck = ProcessInfo.processInfo.environment["SKIP_SIMULATOR_CHECK_FOR_TESTS"] == "true" + let isCorrectSimulator = UIDevice.current.name == "iPhone 16 Pro" && UIDevice.current.systemVersion == "18.1" + if !shouldSkipSimulatorCheck, !isCorrectSimulator { assertionFailure( """ Tests must be run using iOS 18.1 on an iPhone 16 Pro simulator. diff --git a/Scripts/generate_test_plans.sh b/Scripts/generate_test_plans.sh new file mode 100755 index 000000000..8ac737eb5 --- /dev/null +++ b/Scripts/generate_test_plans.sh @@ -0,0 +1,59 @@ +#!/bin/bash + +PROJECT_PATH="Bitwarden.xcodeproj" +TEST_PLAN_UNIT_PATH="TestPlans/TestPlan-Unit.xctestplan" +TEST_PLAN_SNAPSHOT_PATH="TestPlans/TestPlan-Snapshot.xctestplan" +SNAPSHOT_TESTS_TARGET="BitwardenSharedTests" + +mint install atakankarsli/xctestplanner@v1.0.9 + +echo "🧱 Getting test files and adding test to plans if needed..." +echo "--------" + +TEST_FILES=$(find ./BitwardenShared -name '*Tests*' -type f) +if [ -z "$TEST_FILES" ]; then + echo "ℹ️ No test files found." + exit 1 +fi + +for FILE in $TEST_FILES; do + # Get the tests that start with "test_snapshot_" + TESTS=$(grep -E '^\s*func\s+test_snapshot_' $FILE | awk '{print $2}' | awk -F'(' '{print $1}') + if [ -z "$TESTS" ]; then + continue + fi + + for TEST in $TESTS; do + # Get the class name, there are some classes with "final" applied so we need to check that as well + # to get the correct class name. + CLASS_NAME=$(grep -B 5000 "func $TEST" $FILE | grep "class " | tail -n 1 | awk '{print $2}' | awk -F':' '{print $1}') + if [[ "$CLASS_NAME" == "class" ]]; then + CLASS_NAME=$(grep -B 5000 "func $TEST" $FILE | grep "final class " | tail -n 1 | awk '{print $3}' | awk -F':' '{print $1}') + fi + + ENTRY_PATTERN_TO_CHECK_IF_EXISTS="${CLASS_NAME}.*${TEST}()" + ENTRY="${CLASS_NAME}/${TEST}()" + + # Select snapshot tests in the Snapshot test plan. + if ! grep -qE $ENTRY_PATTERN_TO_CHECK_IF_EXISTS $TEST_PLAN_SNAPSHOT_PATH; then + mint run atakankarsli/xctestplanner@v1.0.9 select $ENTRY -f $TEST_PLAN_SNAPSHOT_PATH + echo "🧪 $ENTRY added to selected tests in snapshot test plan." + fi + + # Skip snapshot tests in the Unit test plan. + if ! grep -qE $ENTRY_PATTERN_TO_CHECK_IF_EXISTS $TEST_PLAN_UNIT_PATH; then + mint run atakankarsli/xctestplanner@v1.0.9 skip $ENTRY -f $TEST_PLAN_UNIT_PATH + echo "🧪 $ENTRY added to skipped tests in unit test plan." + fi + done +done + +# WORKAROUND: Currently, there is no way to select/skip test per target so they are being added to all targets +# so we need to remove them from all the targets except "BitwardenSharedTests" in the Unit test plans. +TEMP_OUTPUT_FILE="TestPlans/TestPlan-UnitTemp.xctestplan" + +jq '(.testTargets[]) |= if .target.name != "BitwardenSharedTests" then del(.skippedTests) else . end' "$TEST_PLAN_UNIT_PATH" > "$TEMP_OUTPUT_FILE" + +mv "$TEMP_OUTPUT_FILE" "$TEST_PLAN_UNIT_PATH" + +echo "🧱 Tests added successfully." diff --git a/TestPlans/TestPlan-Default.xctestplan b/TestPlans/TestPlan-Default.xctestplan new file mode 100644 index 000000000..3752a2b83 --- /dev/null +++ b/TestPlans/TestPlan-Default.xctestplan @@ -0,0 +1,62 @@ +{ + "configurations" : [ + { + "id" : "1F1B495F-A80E-4BEF-8B13-35C0D33C74E9", + "name" : "DefaultConfig", + "options" : { + + } + } + ], + "defaultOptions" : { + "language" : "en", + "region" : "US", + "testExecutionOrdering" : "random", + "testTimeoutsEnabled" : true + }, + "testTargets" : [ + { + "target" : { + "containerPath" : "container:Bitwarden.xcodeproj", + "identifier" : "1ACA591B401F3A38DB33C366", + "name" : "BitwardenSharedTests" + } + }, + { + "target" : { + "containerPath" : "container:Bitwarden.xcodeproj", + "identifier" : "417A98C7A214F8B5F141E702", + "name" : "BitwardenAutoFillExtensionTests" + } + }, + { + "target" : { + "containerPath" : "container:Bitwarden.xcodeproj", + "identifier" : "8E852F2FEA58332906A444C6", + "name" : "BitwardenActionExtensionTests" + } + }, + { + "target" : { + "containerPath" : "container:Bitwarden.xcodeproj", + "identifier" : "2AA7964F64AD34FCAE257E17", + "name" : "BitwardenTests" + } + }, + { + "target" : { + "containerPath" : "container:Bitwarden.xcodeproj", + "identifier" : "A046C66D01BE50457BEC672C", + "name" : "AuthenticatorBridgeKitTests" + } + }, + { + "target" : { + "containerPath" : "container:Bitwarden.xcodeproj", + "identifier" : "C026D25C368010616A94990A", + "name" : "BitwardenShareExtensionTests" + } + } + ], + "version" : 1 +} diff --git a/TestPlans/TestPlan-Snapshot.xctestplan b/TestPlans/TestPlan-Snapshot.xctestplan new file mode 100644 index 000000000..5ded32cb7 --- /dev/null +++ b/TestPlans/TestPlan-Snapshot.xctestplan @@ -0,0 +1,29 @@ +{ + "configurations" : [ + { + "id" : "AE7F8439-11C3-4A5A-AB62-C322355EE6A5", + "name" : "DefaultConfig", + "options" : { + + } + } + ], + "defaultOptions" : { + "language" : "en", + "region" : "US", + "testTimeoutsEnabled" : true + }, + "testTargets" : [ + { + "selectedTests" : [ + + ], + "target" : { + "containerPath" : "container:Bitwarden.xcodeproj", + "identifier" : "1ACA591B401F3A38DB33C366", + "name" : "BitwardenSharedTests" + } + } + ], + "version" : 1 +} diff --git a/TestPlans/TestPlan-Unit.xctestplan b/TestPlans/TestPlan-Unit.xctestplan new file mode 100644 index 000000000..9153f2804 --- /dev/null +++ b/TestPlans/TestPlan-Unit.xctestplan @@ -0,0 +1,67 @@ +{ + "configurations" : [ + { + "id" : "7F1F3659-44A5-4DB0-8565-F699A65B2C7D", + "name" : "DefaultConfig", + "options" : { + + } + } + ], + "defaultOptions" : { + "environmentVariableEntries" : [ + { + "key" : "SKIP_SIMULATOR_CHECK_FOR_TESTS", + "value" : "true" + } + ], + "language" : "en", + "region" : "US", + "testTimeoutsEnabled" : true + }, + "testTargets" : [ + { + "target" : { + "containerPath" : "container:Bitwarden.xcodeproj", + "identifier" : "C026D25C368010616A94990A", + "name" : "BitwardenShareExtensionTests" + } + }, + { + "target" : { + "containerPath" : "container:Bitwarden.xcodeproj", + "identifier" : "1ACA591B401F3A38DB33C366", + "name" : "BitwardenSharedTests" + } + }, + { + "target" : { + "containerPath" : "container:Bitwarden.xcodeproj", + "identifier" : "417A98C7A214F8B5F141E702", + "name" : "BitwardenAutoFillExtensionTests" + } + }, + { + "target" : { + "containerPath" : "container:Bitwarden.xcodeproj", + "identifier" : "2AA7964F64AD34FCAE257E17", + "name" : "BitwardenTests" + } + }, + { + "target" : { + "containerPath" : "container:Bitwarden.xcodeproj", + "identifier" : "8E852F2FEA58332906A444C6", + "name" : "BitwardenActionExtensionTests" + } + }, + { + "target" : { + "containerPath" : "container:Bitwarden.xcodeproj", + "identifier" : "A046C66D01BE50457BEC672C", + "name" : "AuthenticatorBridgeKitTests" + } + } + ], + "version" : 1 +} diff --git a/project.yml b/project.yml index 4008c7037..0b384fb4d 100644 --- a/project.yml +++ b/project.yml @@ -50,6 +50,10 @@ schemes: gatherCoverageData: true targets: - AuthenticatorBridgeKitTests + testPlans: + - path: TestPlans/TestPlan-Default.xctestplan + defaultPlan: true + - path: TestPlans/TestPlan-Unit.xctestplan Bitwarden: build: targets: @@ -78,6 +82,11 @@ schemes: - BitwardenShareExtensionTests - BitwardenSharedTests - package: Networking/NetworkingTests + testPlans: + - path: TestPlans/TestPlan-Default.xctestplan + defaultPlan: true + - path: TestPlans/TestPlan-Unit.xctestplan + - path: TestPlans/TestPlan-Snapshot.xctestplan BitwardenActionExtension: build: targets: @@ -91,6 +100,10 @@ schemes: region: US targets: - BitwardenActionExtensionTests + testPlans: + - path: TestPlans/TestPlan-Default.xctestplan + defaultPlan: true + - path: TestPlans/TestPlan-Unit.xctestplan BitwardenAutoFillExtension: build: targets: @@ -104,6 +117,10 @@ schemes: region: US targets: - BitwardenAutoFillExtensionTests + testPlans: + - path: TestPlans/TestPlan-Default.xctestplan + defaultPlan: true + - path: TestPlans/TestPlan-Unit.xctestplan BitwardenShareExtension: build: targets: @@ -117,6 +134,10 @@ schemes: region: US targets: - BitwardenShareExtensionTests + testPlans: + - path: TestPlans/TestPlan-Default.xctestplan + defaultPlan: true + - path: TestPlans/TestPlan-Unit.xctestplan BitwardenShared: build: targets: @@ -132,6 +153,10 @@ schemes: region: US targets: - BitwardenSharedTests + testPlans: + - path: TestPlans/TestPlan-Default.xctestplan + defaultPlan: true + - path: TestPlans/TestPlan-Unit.xctestplan BitwardenWatchApp: build: targets: