rosterdev 0.1.0

rosterdev 0.1.0

Christopher Prince 维护。



rosterdev 0.1.0

  • crspybits

rosterdev

示例

要运行示例项目,请克隆仓库,然后从示例目录运行 pod install

要求

安装

rosterdev 通过 CocoaPods 提供。要安装它,请将以下行添加到您的 Podfile 中:

pod 'rosterdev', '~> 0.1'

目的是这些开发功能仅在应用的调试构建中可用。在 Swift 中,您可以 为调试构建创建 DEBUG OTHER_SWIFT_FLAGS 以实现这一点。

在您的代码中,执行以下操作:

import rosterdev

您还需要启用开发者仪表板显示。一种方法是通过摇晃手势。请参见 此处示例

#if DEBUG
extension UIWindow {
    override open func motionBegan(_ motion: UIEventSubtype, with event: UIEvent?) {
        if motion == .motionShake {
            if let rootVC = UIApplication.shared.keyWindow?.rootViewController {
                RosterDevVC.show(fromViewController: rootVC, rowContents: [], options: .all)
            }
        }
    }
}
#endif

在上面的示例中,如果您想在开发者仪表板中添加额外的自定义行,您需要向 rowContents: 参数提供一个非空列表。

示例代码中的 DebugDashboardData 类提供了一个示例。

class DebugDashboardData {
    private init() {
    }
    
    static let session = DebugDashboardData()
    
    var debugDashboardExampleSection: [RosterDevRowContents] = {
        var useDev = RosterDevRowContents(name: "Use staging environment", action: { parentVC in
            // Need to do something to setup staging environment
        })
        var useProd = RosterDevRowContents(name: "Use prod environment", action: { parentVC in
            // Need to do something to setup prod environment
        })
        
        return [useDev, useProd]
    }()
    
    func sections() -> [[RosterDevRowContents]] {
        return [debugDashboardExampleSection]
    }
}

要使用此类,请使用 DebugDashboardData.session.sections() 作为 RosterDevVC.showrowContents 参数。

如果您正在进行测试注入,则需要在您的 AppDelegate 中。

#if DEBUG
    TestCases.setup()
#endif

请参见 此处示例

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
#if DEBUG
    TestCases.setup()
#endif
        return true
    }

其中 TestCases 看起来像这样:

import Foundation
import rosterdev

class TestCases {
    private init() {
    }
    
    static let session = TestCases()
    
    static func setup() {
        _ = session
    }
    
    // Make these text names fairly short. They are presented in a UI.
    
    let testFail1 = RosterDevInjectTest.define(testCaseName: "Endpoint1Failure")
    let testFail2 = RosterDevInjectTest.define(testCaseName: "Endpoint2Failure")
    ...
}

当然,您还需要在代码中注入一些实际的测试。例如,它看起来可能像这样:

RosterDevInjectTest.if(TestCases.session.testFail1) {
    // This will only get executed if the DEBUG flag is set AND testFail1 is turned on from the developer dashboard.
    // So, do whatever test injection you need to do here.
}

作者

crspybits, [email protected]

许可协议

rosterdev 在MIT许可协议下可用。有关更多信息,请参阅LICENSE文件。