我正在尝试对一个依赖于另一个类的方法进行单元测试.该方法在该类上调用一个类方法,基本上是这样的:
func myMethod() {
//do stuff
TheirClass.someClassMethod()
}
Run Code Online (Sandbox Code Playgroud)
使用依赖注入技术,我希望能够用模拟替换"TheyClass",但我无法弄清楚如何做到这一点.有没有办法传入模拟类(不是实例)?
编辑:感谢您的回复.也许我应该提供更多细节.我试图模拟的类方法是在一个开源库中.
以下是我的方法.我试图测试它,同时嘲笑呼叫NXOAuth2Request.performMethod.此类方法发出网络调用以从后端获取经过身份验证的用户的信息.在闭包中,我将此信息保存到开源库提供的全局帐户存储中,并发布成功或失败的通知.
func getUserProfileAndVerifyUserIsAuthenticated() {
//this notification is fired when the refresh token has expired, and as a result, a new access token cannot be obtained
NSNotificationCenter.defaultCenter().addObserver(self, selector: "didFailToGetAccessTokenNotification", name: NXOAuth2AccountDidFailToGetAccessTokenNotification, object: nil)
let accounts = self.accountStore.accountsWithAccountType(UserAuthenticationScheme.sharedInstance.accountType) as Array<NXOAuth2Account>
if accounts.count > 0 {
let account = accounts[0]
let userInfoURL = UserAuthenticationScheme.sharedInstance.userInfoURL
println("getUserProfileAndVerifyUserIsAuthenticated: calling to see if user token is still valid")
NXOAuth2Request.performMethod("GET", onResource: userInfoURL, usingParameters: nil, …Run Code Online (Sandbox Code Playgroud) 我正在使用Visual Studio Team Services构建我的应用程序。当我尝试运行单元测试时,出现错误:
xcodebuild: error: option 'Destination' requires at least one parameter of the form 'key=value'
Run Code Online (Sandbox Code Playgroud)
这是在升级到Xcode 8.3之后开始的。构建服务器有8.3,但是当我运行单元测试时,它想使用8.2仿真器。这失败了。
当我尝试使用该-destination开关明确指定8.3仿真器时,它将失败。
-destination "platform=iOS Simulator,name=iPad Pro (9.7 inch),OS=10.3"
Run Code Online (Sandbox Code Playgroud)
我也尝试过在目的地周围使用撇号',没有引号或撇号,以及模拟器ID,但没有任何帮助。没有引号,我得到这个错误:
xcodebuild: error: Unknown build action 'Pro'.
Run Code Online (Sandbox Code Playgroud) 是否可以将UICollectionView中的滚动限制为集合中项目的子集?
我有一个UICollectionView,一次显示一个项目.每个项目占据屏幕的整个宽度.用户可以在项目之间水平滚动.
有时我希望能够限制用户根据特定条件在项目子集之间滚动.
例如,视图可能包含项目1到20,但我只希望用户能够在项目7和9之间滚动.
我已经尝试将contentSize更改为显示所需项目所需的宽度,然后更改contentOffset,但这不起作用.
当用户注册或登录时出现错误,并在输出中收到此错误“此类与键 containerView 的键值编码不兼容”。这是登录代码,注册也有相同的错误,我确定这是正确的代码。
import UIKit
import Firebase
class LoginViewController: UIViewController {
@IBOutlet var Aemeil: UITextField!
@IBOutlet var Apassword: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
}
@IBAction func login (_ sender : Any){
guard let email = Aemeil.text, let password = Apassword.text
else {
print("Form is not valid")
return
}
Auth.auth().signIn(withEmail: email , password: password , completion: { (user,error) in
if error == nil{
let vc = self.storyboard?.instantiateViewController(withIdentifier: "AHome");
self.present(vc!, animated: true, completion: nil);
print("Home page open")
}
else{
let alertController …Run Code Online (Sandbox Code Playgroud)