yonaskolb / XcodeGen

A Swift command line tool for generating your Xcode project
MIT License
6.99k stars 816 forks source link

The flag -testPlan <name> cannot be used since the scheme does not use test plans #1252

Open NikStrela opened 2 years ago

NikStrela commented 2 years ago

Good day! I have a problem setting up test plans.

I have a MyProject project and tests are attached to it. accordingly, I create a test plan(smoke.xctestplan) that includes some of these tests MyProjectUITests.

But when I enter the command:

xcodebuild -showTestPlans -scheme MyProject

Output:

The scheme "MyProject" is not configured to use test plans.

When I enter the command:

xcodebuild -workspace MyProject.xcworkspace -scheme MyProject -destination 'platform=iOS Simulator,name=iPhone 11 Pro Max' test -testPlan smoke

Output:

The flag -testPlan <name> cannot be used since the scheme does not use test plans

I'm guessing I misconfigured the file I'm project.yml

I am attaching the config file below.

Thanks, any advice would be appreciated!

name: MyProject

options:
  defaultConfig: Release
  groupSortPosition: bottom
  transitivelyLinkDependencies: false

configs:
  Debug: debug
  Release: release
  Test: debug

attributes:
  ORGANIZATIONNAME: Uma.tech

packages:
  Swinject:
    url: https://github.com/Swinject/Swinject
    minorVersion: 2.7.1
  GIDSDK:
    url: https://gitlab.zxz.su/mbushuev/gidsdk.pod.git
    minorVersion: 0.1.11
  CryptoSwift:
    url: https://github.com/krzyzanowskim/CryptoSwift.git
    minorVersion: 1.5.1

options:
  postGenCommand: pod install
targets:
  MyProject:
    scheme:
      testTargets:
        - MyProjectTests
        - MyProjectUITests
      testPlans:
        - path: smoke.xctestplan
          defaultPlan: true
    type: application
    platform: iOS
    deploymentTarget: 11.0
    name: MyProject
    sources:
      - ./MyProject
      - path: ./Localizable.stringsdict
      - path: ./MyProject/MyProject.entitlements
      - path: ./MyProject/Info.plist
      - path: ./MyProject/Resources/Assets.xcassets
        buildPhase: resources
    templates: [Shared]
    entitlements:
      path: ./MyProject/MyProject.entitlements
      properties:
        com.apple.security.application-groups: [group.one.myProject]
        com.apple.developer.associated-domains: [applinks:*.myProject.ru, applinks:www.myProject.ru, applinks:myProject.ru, applinks:*.myProject.one, applinks:www.myProject.one, applinks:myProject.one]
        keychain-access-groups: [$(AppIdentifierPrefix)ru.gpmrtv.svod]
        aps-environment: development
        com.apple.smoot.subscriptionservice: true
    settings:
      base:
        ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES: YES
        ASSETCATALOG_COMPILER_APPICON_NAME: "AppIcon"
        CODE_SIGN_ENTITLEMENTS: "MyProject/MyProject.entitlements"
        CLANG_ENABLE_MODULES: YES
        CODE_SIGN_IDENTITY: "iPhone Distribution"
        CODE_SIGN_STYLE: Manual
        CURRENT_PROJECT_VERSION: 1
        DEBUG_INFORMATION_FORMAT: "dwarf-with-dsym"
        DEVELOPMENT_TEAM: 7LYWWLCN92
        FRAMEWORK_SEARCH_PATHS:
          - "$(inherited)"
          - "$(PROJECT_DIR)/UmaPlayerFramework"
        GCC_NO_COMMON_BLOCKS: NO
        GCC_WARN_INHIBIT_ALL_WARNINGS: NO
        INFOPLIST_FILE: ./MyProject/Info.plist
        LD_RUNPATH_SEARCH_PATHS:
          - "$(inherited)"
          - "@executable_path/Frameworks"
          - "@loader_path/Frameworks"
        LLVM_LTO: NO
        MARKETING_VERSION: 2.34.0
        PRODUCT_BUNDLE_IDENTIFIER: ru.gpmrtv.svod
        PROVISIONING_PROFILE_SPECIFIER: "iOS_AppStore"
        SWIFT_OBJC_BRIDGING_HEADER: "MyProject-Bridging-Header.h"
        SWIFT_VERSION: 5.0
        TARGETED_DEVICE_FAMILY: 1,2
        iOS_DEPLOYMENT_TARGET: 11.0
        GCC_PREPROCESSOR_DEFINITIONS:
          - "$(inherited)"
          - "COCOAPODS=1"
        OTHER_CODE_SIGN_FLAGS: --timestamp
        DEFINES_MODULE: YES
        ENABLE_BITCODE: NO
      configs:
        ENABLE_SWIFTLINT: NO
        Test:
          SWIFT_ACTIVE_COMPILATION_CONDITIONS: TEST
    dependencies:
      - framework: ./UmaPlayerFramework/UmaFoundation.xcframework
        embed: true
      - framework: ./UmaPlayerFramework/UmaDownloader.xcframework
        embed: true
      - framework: ./UmaPlayerFramework/UmaMedia.xcframework
        embed: true
      - framework: ./UmaPlayerFramework/UmaSentry.xcframework
        embed: true
      - package: Swinject
      - package: GIDSDK
      - package: CryptoSwift

  MyProjectTests:
    type: bundle.unit-test
    platform: iOS
    name: MyProjectTests
    sources:
      - ./MyProjectTests
    settings:
      base:
        BUNDLE_LOADER: "$(TEST_HOST)"
        TEST_HOST: "$(BUILT_PRODUCTS_DIR)/MyProject.app/MyProject"
    dependencies:
      - target: MyProject

  MyProjectUITests:
    type: com.apple.product-type.bundle.ui-testing
    platform: iOS
    name: MyProjectUITests
    deploymentTarget: 13.0
    sources:
      - ./MyProjectUITests
    dependencies:
      - target: MyProject

schemes:
  MyProject:
    build:
        targets:
            MyProject: all
    test:
      targets:
        - MyProjectUITests
      testPlans:
        - path: smoke.xctestplan
          defaultPlan: true

targetTemplates:
  Shared:
    preBuildScripts:
      - script: |
          if [ "$CONFIGURATION" == "Debug" ] || [ "$CONFIGURATION" == "Test" ] ; then
          echo "Skip frameworks cleaning in debug version"
          exit 0
          fi

          APP_PATH="${TARGET_BUILD_DIR}/${WRAPPER_NAME}"

          # This script loops through the frameworks embedded in the application and
          # removes unused architectures.
          find "$APP_PATH" -name '*.framework' -type d | while read -r FRAMEWORK
          do
          FRAMEWORK_EXECUTABLE_NAME=$(defaults read "$FRAMEWORK/Info.plist" CFBundleExecutable)
          FRAMEWORK_EXECUTABLE_PATH="$FRAMEWORK/$FRAMEWORK_EXECUTABLE_NAME"
          echo "Executable is $FRAMEWORK_EXECUTABLE_PATH"

          EXTRACTED_ARCHS=()

          for ARCH in $ARCHS
          do
          echo "Extracting $ARCH from $FRAMEWORK_EXECUTABLE_NAME"
          lipo -extract "$ARCH" "$FRAMEWORK_EXECUTABLE_PATH" -o "$FRAMEWORK_EXECUTABLE_PATH-$ARCH"
          EXTRACTED_ARCHS+=("$FRAMEWORK_EXECUTABLE_PATH-$ARCH")
          done

          echo "Merging extracted architectures: ${ARCHS}"
          lipo -o "$FRAMEWORK_EXECUTABLE_PATH-merged" -create "${EXTRACTED_ARCHS[@]}"
          rm "${EXTRACTED_ARCHS[@]}"

          echo "Replacing original executable with thinned version"
          rm "$FRAMEWORK_EXECUTABLE_PATH"
          mv "$FRAMEWORK_EXECUTABLE_PATH-merged" "$FRAMEWORK_EXECUTABLE_PATH"

          done
        name: "Run script"
yonaskolb commented 2 years ago

HI @NikStrela, can you confirm the XcodeGen version you're on. Perhaps it's an older one

xcodegen version
NikStrela commented 2 years ago

IMG_0027

brunomdac commented 1 year ago

Hey! I'm having the same issue! Has it been fixed?

Lutzifer commented 1 year ago

I had the same issue today.

The solution in my case was to remove the testTargets definition on the scheme of the AppTarget:

Screenshot 2023-07-11 at 12 25 10

@yonaskolb Maybe they are generated after the testplan and overwrite the

<TestPlans>
         <TestPlanReference
            reference = "Container:Testplan.testplan"
            default = "YES">
         </TestPlanReference>
      </TestPlans>

entry in the xcscheme file?