XcodeBuildMCP icon indicating copy to clipboard operation
XcodeBuildMCP copied to clipboard

Adding Unit Testing Tool for iOS

Open joelklabo opened this issue 8 months ago • 9 comments

Adding tools to run unit tests on iOS.

The error reporting could be improved but it successfully indicates which test fails when run.

image

joelklabo avatar Apr 29 '25 13:04 joelklabo

#9

joelklabo avatar Apr 29 '25 13:04 joelklabo

Thanks for this will look at this later!

cameroncooke avatar Apr 29 '25 15:04 cameroncooke

Thank you for the project!

joelklabo avatar Apr 29 '25 16:04 joelklabo

@joelklabo I've had a quick scan and it looks good, I need to take a deeper look later and will get back to you. I hope to have some time this evening.

cameroncooke avatar Apr 30 '25 11:04 cameroncooke

@joelklabo I've added some tests to the example projects, run the linter and formatted and removed some unused imported symbols.

I think the executeXcodeBuild function needs refactoring to improve how it parses output to make it more robust and identify build failure vs test failure, though I'm not clear currently on how to identify this. I was hoping we could use exit codes but it seems the test failure and build failure exit code is the same (65) 🤦‍♂️

Screenshot 2025-04-30 at 21 22 12

executeXcodeBuild is already responsible for parsing warnings and errors, so I think it should also parse test result bundles. We can then parse them using xcrun xcresulttool and then return the test failures in the ToolResponse.Content field instead of exposing the rawOutput to the calling function.

cameroncooke avatar Apr 30 '25 20:04 cameroncooke

@joelklabo I've added some tests to the example projects, run the linter and formatted and removed some unused imported symbols.

I think the executeXcodeBuild function needs refactoring to improve how it parses output to make it more robust and identify build failure vs test failure, though I'm not clear currently on how to identify this. I was hoping we could use exit codes but it seems the test failure and build failure exit code is the same (65) 🤦‍♂️

Screenshot 2025-04-30 at 21 22 12 `executeXcodeBuild` is already responsible for parsing warnings and errors, so I think it should also parse test result bundles. We can then parse them using `xcrun xcresulttool` and then return the test failures in the `ToolResponse.Content` field instead of exposing the `rawOutput` to the calling function.

I think we can just look for the presence of an xcresultbundle when the test command returns code 65, if it is a build failure, then the bundle won't exist.

I'm not sure when I'm going to have time to look into this, I'm afraid. You're welcome to take a sta,b otherwise I'll get on it as soon as I can so we can get this PR merged in.

cameroncooke avatar Apr 30 '25 21:04 cameroncooke

I've not forgotten about this been super busy recently and only have a few hours a day to focus on this. I will get this merged in.

cameroncooke avatar May 02 '25 09:05 cameroncooke

Yeah, same here, I agree with your comments. I'll take a stab at it if I can find time today

joelklabo avatar May 02 '25 16:05 joelklabo

Just wanted to +1 this! Would love to see this added soon. Thanks for the great tools already, they work really well. Would love to help in any way I can.

reftonull avatar May 20 '25 17:05 reftonull

also waiting for this feature

mmbabaev avatar Jun 04 '25 10:06 mmbabaev

Thanks for your contribution, this has now been implemented, so I am closing this PR. Thanks again!

cameroncooke avatar Jun 07 '25 20:06 cameroncooke

Thanks for implementing it @cameroncooke !

joelklabo avatar Jun 07 '25 20:06 joelklabo