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

1.9k views Asked by At

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.

3

There are 3 answers

4
förschter On BEST ANSWER

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.

0
Davide Tamiazzo On

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

0
Tamara Suslova On

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.