Record UI Test disabled in Xcode - ios

Record UITest button is disabled in Xcode
Deleted derived data, clean the build not solving this problem
It's working fine with Xcode 10.1
Is there anything i'm missing?

I see this a lot as well.
For starters, here is how my class looks after immediately creating the test function:
Notice the following:
No record button available, matching OP
The diamond indicating it is a test does not appear on the left column
I then run my tests, but stop immediately. Doing that gives me this:
I can now record
The diamond appears on the left column
You can also shut down Xcode and restart, but the above steps are faster.

Related

Including a Playground in my project

I'm working in Xcode 9 on a Swift project, and I'm in table flipping mode with this.
Here's my end goal: put my tests next to my logic in a playground so that as I write the logic, I can see the tests pass in close to real time.
I will also accept how to put my tests in a playground by themselves, I just don't want to be running tests on a simulator for every little thing.
My problems in trying to get this to work are many. First and foremost, I can't find a way to add a playground directly to my project/workspace. When I right click on a group in the project navigator and select 'New file...' I get this:
As you can see, no option for playground. Filtering also returns no results. If I press the plus button at the bottom of the project navigator, the same dialog (with no playground option) pops up.
I thought it's in another menu so I went to the File menu, and in "New >" I find an option for creating a playground. I select a blank playground from the chooser, choose where to save it (strange that it wanted to save it under 'Unsaved Xcode Documents') and a basic playground comes up in a new tab. Odd thing I notice, though, is that there's no longer a play button or scheme/simulator selector at the top on this tab.
It now doesn't recognize ANY modules other than Apple provided ones! And sure enough, creating the playground didn't actually add it to my workspace. I guess I have to manually add it to my project. Upon doing so, it will recognize my pods but none of my project files! Any class I try to use gives me an Unrecognized identifier. Trying to import my project doesn't work either, it just gives me a No module.
I tried clearing DerivedData, I tried cleaning, I tried restarting Xcode, I even made sure I had an iPad Pro in the list of simulators (since that seems to matter for some people).
In frustration, I deleted the playground, and resolved just to deal with running my tests constantly. But now, my project has persistent errors! Despite moving the playground to the trash, Swift continues to error saying 'Unresolved identifier' for that playground!
As the excellent Brandon Williams says in his talk at FrenchKit, a playground "does not get access to anything in the application target." Which is ridiculous, but hey, what are you gonna do. So the answer is: there is currently no way to do this the way I asked.
It IS possible, however, to achieve this functionality if your logic is in its own framework/cocoapod. That is, move the logic you want to test out of your app target and into an outside library that your app, subsequently, imports. This will allow your playground to import it as well, and you can test to your heart's content.

Xcode: unit tests are misbehaving

I'm working on an app for iOS. I have 3 targets:
App — the app itself
AppTests — unit tests
AppUITests — UI tests
The third one is currently empty, but I intend to use it later. There are lots of tests in the second one.
Before yesterday, when I pressed Cmd+U, Xcode would happily run all tests for me (on a simulator, usually), and give me comprehensive report in the Debug area down below.
All of a sudden that changed. Now I see output from unit tests (AppTests) for less than a second, then it disappears, and a bit later the output from UI tests appears instead — which is completely useless, since there are no UI tests.
I'm not OK with this. UI tests sometimes print valuable information (not normally, but sometimes I use that). I need to see this output. And I kinda can: I see that it's still there in the log file, like DerivedData/App/Logs/Test/<long-guid-here>/Session-2016-06-16_18\:34\:44-EjeDwZ.log, along with lots and lots of other information that I don't understand. And there is another file, like Session-2016-06-16_18:34:44-Wlv6KP.log, in the same folder, with, as it seems, output from UI tests.
I want to see both, as it was before. I'm not OK with grepping through the giant log file.
What I tried:
Removing DerivedData folder entirely.
Cloning the same project from git into a new directory and starting it from there.
Reverting to an earlier version of the code, which worked fine before.
Removing ~/Library/Caches/com.apple.dt.*.
Trying tests on a different simulator.
Doesn't matter.
Another symptom is that the "Tests" panel in Xcode doesn't work anymore. It still correctly displays test suites and tests themselves, but small buttons to the right of tests, intended to run them, don't do anything. I still can run the suite by right-clicking on it and choosing Run AppTests (and I see the output in that case), but not by clicking on buttons. Also, I can run individual tests by clicking on the buttons in the code editor, to the left of test functions.
Does anybody have any idea how to fix it?
Xcode 7.3, Swift, if it matters.
Update:
After fiddling with "Edit Scheme" — specifically, changing "Debug" to "Release", running tests, and then changing back — "Run" buttons in the Tests Navigator suddenly started working. Issue with two different logs still remains, and I have no idea what to make of this.
Update 2:
"Run" buttons stopped working AGAIN, for no obvious reason.
Update 3:
OK, I figured out how to view tests output in the report instead of debug area.

Record button disabled in Xcode UI Test Target

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:
Created a new UI Test target within my project
Ensured that 'Enable Testability' has been set to YES for the target I am testing
Cleaned, cleaned build folder, rebuilt the app, restarted Xcode and everything else I could think of.
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?
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.
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.
Click on 6th button from top of the left pane - Show the test navigator
Right click on the UI tests, then click on "Enable ... "
Then you can record.
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.
I followed all the tips listed here, and the only thing that fixed it was restarting Xcode.
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.
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.
Also, make sure you select the UI test scheme, which was the problem in my case:
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.
create function in yourfileUITests.swift
running program by TEST
your function can record UI Testing, button already enable

Cannot run program in Xcode

I've recently made an app and could successfully run and test it until this suddenly happened,
fail to run program
It doesn't looks like an issue, but the "run" button is unavailable. Usually it should look something like,
successfully run a program
As in the image, first there are two buttons, run and stop, after that there is the name of the program/app and its icon (fun facts) and then the iphone simulator it will run on (iphone 6). On the image on top, the failed to run program attempt, it is totally different, first the run button is disabled, second, the icon is a gear and not the app icon, and third, there is no simulator, it appears "my mac".
I don't know why this happened but this cannot let me run the app. I searched in the apple documentation and didn't found anything. If someone knows how to solve this please tell me.
The simplest solution is to rebuild your project from scratch. This is not difficult because you still have all your code. So, start with a new project from the iOS template. Copy your code from the old project into the new project.
And try to avoid renaming your project from now on, because there is a bug in some versions of Xcode where it crashes and destroys the project in just the way you describe in your question.
And update to the latest version of Xcode, because it is less likely to cause this problem (though in fact I have not found it reliable for renaming projects even now).

Xcode 6 Code Sense stops working after build

So this same problem exists for a long time apparently. I checked all the xcode 4 code sense problems and used their solution and it works. Right up untill I build the file to run and then code sense stops working. I Really dont want to keep deleting the file in organizer and restarting xcode everytime. Is there a simpler method to fix this.
The first thing I always do when I lose Code Sense is to clean the project. If that doesn't work I use Watchdog to clean it. Watchdog deletes the derived data for the project like you can do in Organizer but it allows you to set up a handy keyboard shortcut which saves a ton of time now that Organizer doesn't have a keyboard shortcut.

Resources