【问题标题】:How to use helper methods of one XCTestCase subclass in another XCTestCase subclass?如何在另一个 XCTestCase 子类中使用一个 XCTestCase 子类的辅助方法?
【发布时间】:2014-10-26 19:58:50
【问题描述】:

我有两个 XCTestCase 子类,

  1. @interface SessionTest : XCTestCase
  2. @interface UserTest : XCTestCase

SessionTest 类中,我有辅助方法-(BOOL)Login;

我想在UserTest类中使用这个方法,谁能告诉我如何实现这个功能。

谢谢。

【问题讨论】:

    标签: ios iphone xcode ios7 xctest


    【解决方案1】:

    你可以创建第三个类:

    @interface TestHelper : NSObject
    

    -(BOOL)Login 实现为TestHelper 的方法,并在SessionTestUserTest 中使用它。

    作为可能的解决方案,您可以从SessionTest 继承UserTest

    @interface UserTest : SessionTest
    

    【讨论】:

    • 第二个解决方案如何工作,因为所有测试用例类都有 .m 文件而没有 .h
    • .h 文件缺失与继承无关。 @interface 刚刚在 .m 文件中使用。但动作还是一样
    猜你喜欢
    • 2016-08-06
    • 2015-02-07
    • 2014-07-02
    • 2016-05-18
    • 2019-07-25
    • 2014-01-12
    • 1970-01-01
    • 2015-12-18
    • 2011-03-27
    相关资源
    最近更新 更多