다른 defaultTestSuite 메서드를 변경하여 다른 클래스의 테스트 메서드를 선택하여 특정 순서로 실행할 수있는 클래스를 만들려고합니다. 그러나 나는 다른 테스트 파일에 테스트 파일을 가져올 때마다 나는이 문제를 해결할 수있는 방법 링커 오류둘 이상의 SenTestCase 연결
duplicate symbol _OBJC_METACLASS_$_TMKTestExample
왜이 OCUnit으로 일어나는가를 얻을?
감사
다른 defaultTestSuite 메서드를 변경하여 다른 클래스의 테스트 메서드를 선택하여 특정 순서로 실행할 수있는 클래스를 만들려고합니다. 그러나 나는 다른 테스트 파일에 테스트 파일을 가져올 때마다 나는이 문제를 해결할 수있는 방법 링커 오류둘 이상의 SenTestCase 연결
duplicate symbol _OBJC_METACLASS_$_TMKTestExample
왜이 OCUnit으로 일어나는가를 얻을?
감사
SenTestCase에 속한 testInvocation 메서드에 내 자신의 NSInvocations를 만들어서 해결책을 찾았습니다.
기본적으로 나는 테스트가 실행되면 각 NSInvocation에 설정된 몇 가지 동작 (흐름 테스트 용)을 실행하는 테스트 메서드를 던지는 빈 테스트 클래스를 가지고 메서드는 존재하는 순서와 동일한 순서로 실행됩니다
위 때문에 메서드를 오버라이드 (override) 할 필요가있다 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;
}
을 확장하십시오 testInvocation 정적 방법, 그리고 아래의 원유 예와 비슷한에 가능한 한 많은 방법을 추가 허용 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;
}
는 위의 예제는 하나 개의 테스트를 추가하지만 내가이는이 웹 사이트의 예에서 찍은 무슨 뜻인지 볼 수 있습니다 :
파라미터 테스트 : http://briancoyner.github.io/blog/2011/09/12/ocunit-parameterized-test-case/
있는 NSInvocation을 기구 : https://github.com/aleph7/a-coding/blob/master/ObjC/Invocations/NSInvocation%2BConstructors.m
이 둘을 모두 사용하고 테스트 순서를 조작하면 KIF에 대해 다음을 만들 수 있습니다. - 특정 UIViewController/UIView/etc.에서 테스트 할 동작을 설명하는 클래스를 만든 다음이 메서드를 다시 사용하여 흐름 테스트, 회귀 UI 테스트, 코드 또는 스크립트 (여전히 후자를 수행). - 일반 테스트 클래스.
매우 구체적인 요구 사항이 필요한 사용자에게 도움이되기를 바랍니다.
원래 질문에 대해서는 알아 내지 못했지만 방법이 있는지 궁금합니다.
당신의 TMKTestExample
의 대상 회원, 그것은 주요 대상 및 단위 테스트 대상에 모두 포함되지 않아야 확인합니다.
단위 테스트 대상에만 있습니다. – RicardoDuarte
단위 테스트는 독립 실행 형이어야하며 테스트 실행 순서에 의존하지 않아야합니다. 이 작업을 수행해야하는 이유가 있습니까? – jrturton
저는 KIF를 사용하고 있으며, 테스트 코드를 반복 작성하는 대신 UI 테스트 플로우를 재사용하기 위해 커스텀 테스트 클래스를 재사용하고 싶습니다. – RicardoDuarte