import XCTest
class UnitTestClass: XCTestCase {
override func setUp() {
super.setUp()
// Put setup code here. This method is called before the invocation of each test method in the class.
}
override func tearDown() {
// Put teardown code here. This method is called after the invocation of each test method in the class.
super.tearDown()
}
func testExample() {
}
I have multiple UIViewController classes in my app. Now, i want to test each class by UIAutomation in Xcode 8 ,swift 3. After Searching a lot, i didn't get any useful tutorial or tool in Xcode or swift's latest version. My App's First screen is Login screen. Can anyone help me to find-out the useful solution
I believe UIAutomation was deprecated in Xcode 8. But you can set up UI tests in Xcode 8 by simply doing the following:
Add an iOS UI Testing Bundle target to your project.
Create a test method under the new test file created as part of that target.
Click inside the curly braces within the method.
Click the "record" icon shown below the source editor to start recording your UI actions in the simulator.
Watch this WWDC Video to learn more about UI testing in Xcode.
Related
I am trying to implement UI testing with BDD using Cucumberish framework.
I understand quite well the Feature files parsing system and I managed to tests some UI elements of the main screen.
However I would like to load any controller from storyboard before using UI testing on the corresponding screen.
Here is my initialization code:
#objc class CucumberishSwiftInit: NSObject {
#objc class func CucumberishSwiftInit()
{
var application : XCUIApplication!
//A closure that will be executed just before executing any of your features
beforeStart { () -> Void in
application = XCUIApplication()
}
//A Given step definition
Given("the app is running") { (args, userInfo) -> Void in
application.launch()
let bundle = Bundle.main
// I double checked the storyboard name and I can access it in my Unit Tests target
// application crashes here
let storyboard = UIStoryboard(name: "Main", bundle: bundle)
// never executed
Swift.print("storyboard \(storyboard)")
}
let bundle = Bundle(for: CucumberishSwiftInit.self)
Cucumberish.executeFeatures(inDirectory: "Features", from: bundle, includeTags: nil, excludeTags: ["skip"])
}
}
Some feature file:
#run #welcome
Feature: Some feature
Some feature desc
Scenario: Can load screen
Given the app is running
...
The application crashed on the UIStoryboard init statement, caught "NSInvalidArgumentException", "Could not find a storyboard named 'Main' in bundle NSBundle (loaded). I have no clue why as it is working using with my unit tests.
The error you're getting is due to the fact that the .storyboard file you are trying to load is not part of the bundle of the application you are running.
The reason that's happening is that when you run a UI test your code is not running in the same process as your application, and it can only interact with it through the XCUIApplication proxy. (The mechanics might be slightly different, but that's gist, unfortunately there's little documentation that I can link.)
UI testing is a different style of testing than what you can do with XCTest. Programmatically loading an instance of a screen from a .storyboard is not possible.
In other words, you can't use any code from your app in your UI tests, but rather have to interact with it like a real user would, and write assertions for what's on the screen.
Description
I have a problem with environment variables. When I build my app and it's running, everything goes fine, but when I press "stop" or I archive it for app store, the environment variable returns nil (or an empty string, I'm not quite sure yet).
How to reproduce:
Build the app
Run it on the simulator ("Hello world" will appear)
Stop the app
In the simulator, go back in the app ("Hello word" won't appear)
Minimal reproduction:
class ViewController: UIViewController {
#IBOutlet weak var label: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
label.text = ProcessInfo.processInfo.environment["testVariable"]
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
The label Outlet references a simple storyboard
storyboard screenshot
And here is the config for my env variables
Variables configuration
Finally, here is a minimal reproduction of the problem on a github repo
https://github.com/MasterBroki/test-environment-variable
Thanks for your answers!
Xcode passes environment variables from a scheme to the iOS runtime. When you run the application outside of Xcode, they are not passed. I've also run into this limitation, and you can find a similar question here.
An alternative to this approach is to use pairings of configurations (such as Debug, Release, or one you make for a specific purpose) and "Preprocessor Flags" OR "Other Swift Flags." You can find some guidance for this approach here.
Running into the same problem. Using normal Debug and Release config options with checks like
#if DEBUG
<logic>
#else
<logic>
#endif
works for me
I try to use KIF in swift project. I run test case on iPhone simulator. Probably I did not set up correctly KIF because use it first time. I used this manual
Test fails in this simple code
func testSelectingOrganizerRole() {
tester().tapView(withAccessibilityLabel: "ORGANIZE")
}
with reason:
A button with Accessibility label "ORGANIZE" exists on initial ViewConroller of storyboard.
Why don't you switch to the UI tests framework available since Xcode 7? A quick intro:
UI testing gives you the ability to find and interact with the UI of your app in order to validate the properties and state of the UI elements.
UI testing includes UI recording, which gives you the ability to generate code that exercises your app's UI the same way you do, and which you can expand upon to implement UI tests. This is a great way to quickly get started writing UI tests.
Using this framework, your simple test would look like this:
let app = XCUIApplication()
app.launch()
app["ORGANIZE"].tap()
Using Xcode 7.3, writing Swift program; searched for this topic but could not find an answer. Apologies, in advance. Last program language was COBOL.
Application background:
It is a single view application, User keys in data and at some point the User 'wins' - at that point, two buttons are available: 'Quit?' and 'Play Again?'
For the 'Quit?' button I have:
// MARK: C.This IBAction used to quit the game
#IBAction func quitIt(sender: AnyObject)
{
exit(0)
}
Hopefully, the above is the most efficient way.
What I need help on is the 'Play Again?' button:
// TODO: B. This IBAction used to play another game
#IBAction func Playagain(sender: AnyObject)
{
}
What code do I put in?
Move the startup code for your game to it's own func(tion).
Call that function both from [wherever you moved it from] and also in PlayAgain().
I hope this is for OS X rather than iOS - Apple will probably reject your iOS app if it exits. They consider that "crashing".
https://developer.apple.com/library/ios/qa/qa1561/_index.html
**I have read the RevMob instructions for Swift and I have read an answer to an Swift-RevMob question on here, but it didn't resolve my particular issue. **
I am currently trying to get a fullscreen ad to show.
This is my GameViewController.swift:
verride func viewDidLoad() {
super.viewDidLoad()
//Start RevMob code
let completionBlock: () -> Void = {
// do something when it successfully starts the session
RevMobAds.session().showFullscreen();
}
let errorBlock: (NSError!) -> Void = {error in
// check the error
println(error);
}
RevMobAds.startSessionWithAppID("55770fcc17dd7840727aa5e8",
withSuccessHandler: completionBlock, andFailHandler: errorBlock);
//End of RevMob Code
I have defined the modules in my package as "Yes":
This is my Bridge-Header:
// Use this file to import your target's public headers that you would like to expose to Swift.
#import <RevMobAds/RevMobAds.h>
Lastly, this is the error that I am currently getting when I try to build my code:
Thanks if you can help!
CLBeaconRegion is part of Core Location from iOS 7 on, so you need to make sure the framework is linked in your project.
Note: in my experience, CLBeaconRegion is picked up by Apple as part of app review and they often want to know how you're using beacons – even if the code is just sitting there and you're not planning to use it.
Twice now I have been asked by app review to provide a video of my app detecting a beacon so they can see how it works, so either be prepared to explain your usage or see if there's a library version without it built in.
In addition to the required frameworks, you have to add CoreLocation.framework
I had the same issue. With CoreLocation.framework, also add AVFoundation.framework. Hope that helps