Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 链接两个或多个SenTestCase_Ios_Objective C_Ocunit - Fatal编程技术网

Ios 链接两个或多个SenTestCase

Ios 链接两个或多个SenTestCase,ios,objective-c,ocunit,Ios,Objective C,Ocunit,我试图更改现有的defaultTestSuite方法,以创建一个类,该类可以从不同的类中选择测试方法并按特定顺序执行它们。 但是,每次我在另一个测试文件中导入一个测试文件时,我都会得到一个链接器错误 duplicate symbol _OBJC_METACLASS_$_TMKTestExample 为什么OCUnit会出现这种情况,我该如何解决 关于检查您的TMKTestExample的目标成员资格,它不应同时包含在主目标和单元测试目标中。我通过在属于SenTestCase的testInvoc

我试图更改现有的defaultTestSuite方法,以创建一个类,该类可以从不同的类中选择测试方法并按特定顺序执行它们。 但是,每次我在另一个测试文件中导入一个测试文件时,我都会得到一个链接器错误

duplicate symbol _OBJC_METACLASS_$_TMKTestExample
为什么OCUnit会出现这种情况,我该如何解决


关于

检查您的TMKTestExample的目标成员资格,它不应同时包含在主目标和单元测试目标中。

我通过在属于SenTestCase的testInvocation方法中创建自己的NSInvocation找到了解决方案

基本上我有一个空的测试类,我抛出测试方法来执行流测试的一些操作,这些方法在每个NSInvocation中设置,一旦测试运行,这些方法将按照testInvocation静态方法中存在的相同顺序执行,并且它允许添加尽可能多的方法,与下面的粗略示例类似:

扩展SenTestCase类

- (id) initWithInvocation:(NSInvocation *)anInvocation
{
    id invocationTarget = anInvocation.target;
    self = [super initWithInvocation:anInvocation];

    if (!self) {
        return nil;
    }

    if (invocationTarget != nil && invocationTarget != self) {
        anInvocation.target = invocationTarget;
    }

    return self;

}
有必要重写上述方法,因为在super initWithInvocation方法中,目标将始终设置为self

+(NSArray *) testInvocations
{


    NSMutableArray *invocations = (NSMutableArray *)[super testInvocations];
    TMKTestFirstViewControllerBaseAction *baseAction = [TMKTestFirstViewControllerBaseAction sharedInstance];
    for (int i=0; i<4; i++) {
        NSInvocation *invocation = nil;

        switch (i) {
            case 3:{
                invocation = [NSInvocation invocationWithTarget:baseAction      selector:@selector(tapChangeBackgroundButton)];
                break;
            }
            case 2:{
                invocation = [NSInvocation invocationWithTarget:baseAction selector:@selector(tapChangeBackgroundButton)];
                break;
            }
            case 0:{
                invocation = [NSInvocation invocationWithTarget:baseAction selector:@selector(tapBarButtonWithAccessibilityLabel:)];
                NSString *arg = @"Second";
            [invocation setArgument:&arg atIndex:2];
                break;
            }
            case 1:{
            invocation = [NSInvocation invocationWithTarget:baseAction  selector:@selector(tapBarButtonWithAccessibilityLabel:)];
                NSString *arg = @"First";
                [invocation setArgument:&arg atIndex:2];
                break;
            }
            default:
                break;
        }
        [invocation retainArguments];
        NSLog(@"invocation target: %d target: %@", i,invocation.target);
         [invocations insertObject:invocation atIndex:i+1];


    }

    return invocations;
}
上面的示例只添加了一个测试,但可以看出我的意思,这是从这些网站的示例中获取的:

参数测试:

N位置安装:

使用这两种方法并操纵测试顺序,我能够为KIF创建以下内容: -类,这些类描述要在特定UIViewController/UIView/等中测试的操作,然后重用这些方法,从代码或仍在执行后者的脚本创建流测试、回归UI测试。 -正常的测试课程

我希望这有助于任何需要这个非常具体的要求的人


关于最初的问题,我还没有弄明白,我想知道是否有办法

单元测试应该是独立的,不依赖于测试运行顺序。您需要这样做有什么原因吗?我正在使用KIF,我希望重用自定义测试类来执行UI测试流,而不是反复编写测试代码。