I know the breakpoints. But not known about the thing that look like the diamond. Take a look at the image shown, it is present at lines no. 16, 28 and 33. When I click on that, Xcode compiles the project. It is hard to get some details about that.
The diamonds are symbols to indicate test results.
To use them run the tests by selecting menu item Test from menu Product or pressing ⌘U
Test cases are starts with the method name -(void)testLogin, those methods are mentioned in diamond , we can run that test individully or overall test cases can be run by choosing the target as test.
This can be achieved by long press on the play button, which will provide you with 3 option, in that choose test. This will perform all the test cases and provide you the success or failure test cases
Related
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.
I once asked a question related to XCTests. And in one of the answers I was told that it is a common practice to use a separate test target (other than the main app) when running unit tests (at least, in iOS development). I tried to find some sources about it, but I couldn't
I understand, that it is probably a best practice, so I would really like to understand it. Could someone explain to me why is it important, what benefits do I get from it and how should I go about doing it? Links to some articles explaining the issue will be much appreciated.
P.S. I understand that I need special environment for tests (fake in-memory database, mocked networking layer, etc.), but up until now I managed to achieve it without a separate test host. But I believe that there might be a better way.
To answer your points:
Why is using a separate test target important?
Separation of concerns. A unit test target does not have the same kind of structure as a regular app target - it contains a test bundle, which references the app target under test, as well as the test classes and any helper classes required. It is not a duplicate of the app target with test code added to it - in fact it should not even contain the code under test. This means that you don't have to make any special effort to keep the test target in sync with the main app target - the fact that the test bundle loads the main app handles all that for you. (You made a comment on Richard Ross's answer to your previous q suggesting you've run into the difficulties duplication causes already).
How should I go about doing this? (checked on Xcode 7).
Assuming you are wanting to add a target to an existing project that doesn't have any tests, select the main project, and then click on the '+' beneath the list of targets in the project. You can also use the File->New->Target menu option.
You'll see a menu asking you to choose a template for your new target. Select 'Test' and within test select 'iOS Unit Testing Bundle'.
Check the fields in the next screen - they should be correct by default - but you might want to double check the 'Target to be Tested' field value is correct if you have a lot of targets in the project/workspace. Click 'OK' and you should have a functioning unit test bundle, with an example test that you should be able to run using Apple-U or Product->Test You'll still need to #import the app classes if you're using ObjC.
If you are creating a new project, all you need to do is tick the 'Include Unit Test' box when creating the project - no other steps are required.
Apple Docs (with links to relevant WWDC presentations)
Tutorials. Most of the tutorials around are a bit out of date. But not that much has changed, so just look at the docs and figure it out. The two below might be useful, otherwise just google. From a quick glance, most of them seem to assume that the project had unit tests set up at the beginning
http://www.raywenderlich.com/22590/beginning-automated-testing-with-xcode-part-12 (2012/iOS 6, but the process is still broadly the same. Also deals with Jenkins, Git and running tests from the CLI).
Unit testing in OSX - most recent post - not iOS, I know, but more up to date than most of the iOS tutorials (Oct 2015), and gives step by step instructions (including setting the unit test target in the build schemes, which probably won't be necessary in your case). Probably worth a look anyway.
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
So I downloaded the beta of XCode 7 and I've created some UI tests, but I can't find the functionality of how to take screenshots of my app/UI during the test.
Can someone please help?
UI Testing in Xcode automatically takes screenshots of your app after every step.
Simply go to one of the tests that has already ran (Report Navigator > choose a Test), then start expanding your tests. When you hover your mouse over the steps, you will see eye icons near each step that has a screenshot.
Here's an example... in this case, notice the eye icon at the end of the gray row. If I were to tap on it, I would see a screenshot of the app right when the button in my app was tapped (since the step is Tap the "Button" Button).
If you want to generate screenshots, you can also use snapshot, which describes how to trigger screenshots in UI tests: https://github.com/fastlane/fastlane/tree/master/snapshot#how-does-it-work
It basically rotates the device to .Unknown (Source), which triggers a snapshot without actually modifying your app's state.
Comparing the output with the generated plist file enables you to even properly name the screenshot
Facebook's ios-snapshot-test-case and KIF both run as Unit Tests, and therefore are in the same process as the app. As such, they can directly access views and use something like renderView: or snapshotViewAfterScreenUpdates. Xcode UI Testing runs in a separate process, and therefore cannot directly access the views.
UI Automation, Apple's now-deprecated Javascript UI testing library, had a function calledcaptureScreenWithName.
Unfortunately, the new Xcode UI Testing lacks any similar function in its testing library, which to me seems like a glaring omission and I encourage you to submit a Radar for it, as taking screenshots is fundamental to perceptual difference tests (which it sounds like you're trying to do). I hope (and expect) that able will address this deficiency in later Xcode updates.
In the meantime, there are more creative approaches to taking screenshots. See this stack overflow response for a workaround involving taking the screenshot in the app itself and then sending it to the test process.
I' ve created a tool that saves the tests last n screenshots and generates the JUnit tests results report, parsing TestSummaries plist file from test logs. https://github.com/nacuteodor/ProcessTestSummaries
Maybe, that helps you.
Facebook's FBSnapshotTestCase can be alternative solution:
https://github.com/facebook/ios-snapshot-test-case
I was looking for smart way for always automatically run unit test before start archiving. The idea is that if I start all process (by clicking on archive button or by doing something else) unit test will start running. If unit test succeed, archive process will be started, otherwise not. I know it is nor difficult to do that with using Jenkins, etc. but I would like to have simple config/scheme in Xcode which will do the job.
Has anyone some experiences with that?
Select you scheme and go to edit scheme and select "Build".
Check mark Archive for Unit test case target as shown in below image.
Seems like it's just one setting called "Test after build" in Xcode. Someone posted a blog about it.