I’m using Unity to generate an Xcode project for iOS which by default contains a target with the game, and an xcode unit tests target.
I would like to create UI tests, automatically, by using the UnityEditor.iOS.Xcode’s PBXProject class in a PostBuildProcess function.
I have two files which I’m adding to the project: CustomXcodeUITests.m containing my UI tests logic and the Info.plist file.
I’m calling the following methods:
PBXProject proj = new PBXProject()
proj.ReadFromFile(PBXProject.GetPBXProjectPath(buildPath));
string targetGuid = project.AddTarget(“MyUITests”, “xctest”, “com.apple.product-type.bundle.ui-testing”);
string targetProjectPath = Path.Combine(buildPath, “MyUITests”);
Directory.CreateDirectory(targetProjectPath);
// Copying the CustomXcodeUITests.m and Info.plist file into the created project directory
// The local paths relative to the xcode project source tree
string plistLocalPath= “MyUITests/Info.plist”;
string sourceCodeLocalPath = “MyUITests/CustomXcodeUITests.m”;
// Adding the files into the project
proj.AddFile(plistLocalPath, plistLocalPath);
string sourceCodeFileGuid = project.AddFile(sourceCodeLocalPath, sourceCodeLocalPath);
// Adding the .m file to the build
proj.AddFileToBuild(targetGuid, sourceCodeFileGuid);
// … other flag changes
// … writing the changes;
After the AddFileToBuild gets called, I receive the following error:
Exception: The given path .m does not refer to a file in a known build section
at UnityEditor.iOS.Xcode.PBXProjectData.BuildSectionAny (UnityEditor.iOS.Xcode.PBX.PBXNativeTargetData target, System.String path, Boolean isFolderRef) [0x00241] in /Users/builduser/buildslave/unity/build/External/XcodeAPI/Xcode/PBXProjectData.cs:243
at UnityEditor.iOS.Xcode.PBXProject.BuildSectionAny (UnityEditor.iOS.Xcode.PBX.PBXNativeTargetData target, System.String path, Boolean isFolderRef) [0x0000a] in /Users/builduser/buildslave/unity/build/External/XcodeAPI/Xcode/PBXProject.cs:84
at UnityEditor.iOS.Xcode.PBXProject.AddBuildFileImpl (System.String targetGuid, System.String fileGuid, Boolean weak, System.String compileFlags) [0x0005c] in /Users/builduser/buildslave/unity/build/External/XcodeAPI/Xcode/PBXProject.cs:240
at UnityEditor.iOS.Xcode.PBXProject.AddFileToBuild (System.String targetGuid, System.String fileGuid) [0x00006] in /Users/builduser/buildslave/unity/build/External/XcodeAPI/Xcode/PBXProject.cs:254
I tried to remove that last call to AddFileToBuild and everything else works fine, the project is updated. I even checked the contents of the project.pbxproj file and I couldn’t spot any missing part.
I wasn’t sure if the “xctest” is the correct extension for the new UI Tests target, but according to this webpage, the xctest extension results in having an wrapper.cfbundle as the file type. I checked the project.pbxproject contents for a normal, manually created UI test target and indeed the target file is of wrapper.cfbundle type. But again, I’m not sure if the xctest value is the correct one to pass to the AddTarget method to create an UI test target.
Did someone encounter this issue or does someone know the cause?