xcodebuild: Tests cannot be run because the test plan “Scheme” could not be read
Asked Answered
V

3

5

After converting our tests in one of our schemes "Scheme" to test plans using the "Convert to use Test Plans" function in Xcode 13.4. We cannot run the tests using xcodebuild due to the following error:

xcodebuild: error: Failed to build project Scheme with scheme Scheme.
    Reason: Tests cannot be run because the test plan “Scheme” could not be read.
    Recovery suggestion: Confirm that the file exists and is valid and try again.

Setting the test plan name explicilty using the -testPlan parameter results in the same error message.

The scheme configuration exists in the configured location and can be displayed by Xcode.

Visconti answered 4/8, 2022 at 14:13 Comment(0)
V
3

This seems to happen when the test plan has the same name as your scheme. Changing the name of the test plan to SchemeTestplan has solved the issue.

Curiously this was the default name chosen by Xcode.

Visconti answered 4/8, 2022 at 14:13 Comment(4)
As a side note, build-for-testing for a project with test-plan yields multiple .xctestrun files in the build directory with the format. <Scheme>_<TestPlan>_iphonesimulator<Version>-<Architecture>.xctestplanAlver
in my case, changing name does not helpSchist
@Schist does the test run when running it in xcode?Shetler
Yes it did. Removing and adding the whole thing again fixed the problem immediately for me.Schist
S
4

I've faced with such issue after xcode crash on tests execution(it looks like some data remains in inconsistent state after the crash, git shows no difference).

After removing the test plan from xcode project and just adding it back (through Edit scheme -> Test(tab) -> + (button in Test Plans section) -> Add existing test plan) the error disappeared.

Saprolite answered 29/8, 2023 at 3:53 Comment(2)
Have you tried to delete derived data?Shetler
No, I didn't have to. It looks to be faster and safer for my case to remove/add testplan from the project (cleaning Derived Data increases next build time and for big project it's quite time-consuming)Saprolite
V
3

This seems to happen when the test plan has the same name as your scheme. Changing the name of the test plan to SchemeTestplan has solved the issue.

Curiously this was the default name chosen by Xcode.

Visconti answered 4/8, 2022 at 14:13 Comment(4)
As a side note, build-for-testing for a project with test-plan yields multiple .xctestrun files in the build directory with the format. <Scheme>_<TestPlan>_iphonesimulator<Version>-<Architecture>.xctestplanAlver
in my case, changing name does not helpSchist
@Schist does the test run when running it in xcode?Shetler
Yes it did. Removing and adding the whole thing again fixed the problem immediately for me.Schist
W
0

I've faced the same issue and the cause was the wrong location of the test plan mentioned in .xcschema

<TestPlans>
    <TestPlanReference
        reference = "container:<PathToYourTestPlan>/TestPlan.xctestplan"
        default = "YES">
    </TestPlanReference>
</TestPlans>

You can fix this by deleting and recreating the test plan and making sure you select the correct group as well as the wanted folder:

group selected

Waste answered 26/1, 2024 at 16:12 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.