Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PM-14425] [BEEEP] Add test plans #1106

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion GlobalTestHelpers/Support/BitwardenTestCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๐Ÿค” Should this be

Suggested change
let isCorrectSimulator = UIDevice.current.name == "iPhone 16 Pro" && UIDevice.current.systemVersion != "18.1"
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.
Expand Down
59 changes: 59 additions & 0 deletions Scripts/generate_test_plans.sh
Original file line number Diff line number Diff line change
@@ -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/[email protected]

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/[email protected] 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/[email protected] 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."
62 changes: 62 additions & 0 deletions TestPlans/TestPlan-Default.xctestplan
Original file line number Diff line number Diff line change
@@ -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
}
29 changes: 29 additions & 0 deletions TestPlans/TestPlan-Snapshot.xctestplan
Original file line number Diff line number Diff line change
@@ -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
}
67 changes: 67 additions & 0 deletions TestPlans/TestPlan-Unit.xctestplan
Original file line number Diff line number Diff line change
@@ -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
}
25 changes: 25 additions & 0 deletions project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand Down
Loading