简体   繁体   English

链接两个或多个SenTestCase

[英]Link two or more SenTestCase

I am trying to change the existent defaultTestSuite method to create a class that can pick test methods from different classes and execute them in a specific order. 我试图更改现有的defaultTestSuite方法,以创建一个可以从不同类中选择测试方法并以特定顺序执行它们的类。 However every time I import a test file in another test file i get a linker error 但是,每次我将测试文件导入另一个测试文件时,都会出现链接器错误

duplicate symbol _OBJC_METACLASS_$_TMKTestExample

Why does this happen with OCUnit, how could I fix this? 为什么OCUnit会发生这种情况,我该如何解决?

Regards 问候

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

I found the solution by creating my own NSInvocations in the testInvocation method that belongs to the SenTestCase. 我通过在属于SenTestCase的testInvocation方法中创建自己的NSInvocations来找到解决方案。

Basically i have an empty test Class which i throw test methods that execute some action (for flow testing), which are setup in each NSInvocation, once the test runs, the methods will be executed in the same order as the exist in the testInvocation static method, and it Permits to add as many methods as possible, in something similar to the crude example below: 基本上,我有一个空的测试类,该类抛出引发执行某些操作(用于流测试)的测试方法,这些方法在每个NSInvocation中设置,一旦测试运行,这些方法将按照与testInvocation static中存在的相同顺序执行方法,它允许添加尽可能多的方法,类似于下面的原始示例:

Extend the SenTestCase class 扩展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;

}

It is necessary to override the method above because the target will always be set to self in the super initWithInvocation method. 有必要重写上面的方法,因为在超级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;
}

The example above only adds one test but it is possible to see what I mean, this was taken from examples in these websites: 上面的示例仅添加了一个测试,但是有可能看到我的意思,这取自这些网站中的示例:

Using both of these and manipulating the order of tests, i am able to create the following for KIF: - Classes that describe actions to test in a specific UIViewController/UIView/etc., and then reuse the methods to create flow tests, regression UI tests, from code or from scripts (still doing the latter). 使用这两种方法并控制测试顺序,我可以为KIF创建以下内容:-类,描述在特定的UIViewController / UIView / etc中进行测试的动作,然后重用这些方法来创建流程测试,回归UI从代码或脚本进行测试(仍在进行脚本测试)。 - normal test classes. -正常的考试课程。

I hope this helps whoever needs this very specific requirement. 我希望这对需要此非常具体要求的人有所帮助。

Regarding the original question i haven't figured it out, i wonder if there is a way. 关于最初的问题,我还没有弄清楚,我想知道是否有办法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM