Reputation: 6367
I know similar questions have been posted, but from my investigating, there has not been a solution posted, at least not one that works. I have successfully run UI tests only from sample projects in both Swift and Obj-C.
I am trying (unsuccessfully) to integrate UI tests into an existing Xcode Obj-C project, which seems to be another issue altogether. Here are the steps I have taken:
When I do this, the test target is available but the record button is greyed out (disabled) and there are no play buttons in the gutter to execute the tests. There is nothing visual about the test class that would indicate that it is a test class. When I place my cursor in the test method, the record button remains disabled.
Is there anything I've left out? Anything else to check that might be preventing UI tests?
Upvotes: 22
Views: 9141
Reputation: 10346
If you have this issue in Xcode 16 then possibly the problem is that you are trying to record inside an automatically generated test function which looks like below:
@MainActor
func testExample() throws {
// UI tests must launch the application that they test.
let app = XCUIApplication()
app.launch()
// Use XCTAssert and related functions to verify your tests produce the correct results.
}
But there seems to be a bug in Xcode 16 and if there is @MainActor
before the test function then the record button is disabled, so in this case try to remove/comment the @MainActor
line.
Upvotes: 1
Reputation: 1
if you don't see the rhombuses against the function definition that allows you to run the specific test in your editor, that means something is wrong with Xcode and you should try to reopen it. Helped me. Until you don't see the rhombuses the record button is disabled.
Upvotes: 0
Reputation: 15639
I followed all the tips listed here, and the only thing that fixed it was restarting Xcode.
Upvotes: 20
Reputation: 561
If your project has a test plan (.xctestplan
) then make sure that the new test is enabled. Till then the record button will be disabled. This often happens when you add a new UI Test Case Class. Or when you add new test to existing class which has some of the tests disabled.
Upvotes: 0
Reputation: 54543
Then you can record.
Upvotes: 3
Reputation: 2949
Also, make sure you select the UI test scheme, which was the problem in my case:
Upvotes: 0
Reputation: 688
Upvotes: -1
Reputation: 39091
I realized you had to have your cursor inside the test function you want to record for. I simply clicked inside the test function and the record button got enabled.
Upvotes: 1
Reputation: 321
Record button only gets enabled within a function body.
The function name must start with test
. Like testExample()
.
After changing the name of the function wait for a few seconds for the run icon to appear in the gutter.
Now the record button should appear.
Upvotes: 32
Reputation: 31
Make sure you have at least one test function in your ui test class. For example- func testExample(){}. Then you'll be able to record in that function as you can only run functions as tests if they have test as prefix.
Upvotes: 1
Reputation: 186
Make sure you are in the correct XCTestCase subclass file.
After researching for a time, I found that I was all the time in a extension file (I'm been ordering the flows in extension files). So when I opened the main XCTestCase subclass file (like "YourAppUItests") the record test button has been enabled.
Upvotes: 7
Reputation: 27383
Make sure you can build for the test target successfully.
Go to Product > Test, and make sure the UI Testing test case is run (it is fine if the test case is empty). You should also see the test cases under Test Navigator, or in the app target scheme.
Upvotes: 2