Вопрос

Can someone please tell me that this assert could be optimized? Unit testing in iOS is driving me up the wall. A simple assertion on the count of an NSArray should not be this verbose:

GHAssertEquals([[NSNumber numberWithInt:[caseArray count]] intValue], 
                             [[NSNumber numberWithInt:627] intValue], 
                                              @"array count equals");

EDIT: Suggested line below

GHAssertEquals([caseArray count], 627, @"array count equals");

produces this output:

Reason: Type mismatch -- array count equals

0   CoreFoundation                      0x01cfd02e __exceptionPreprocess + 206
1   libobjc.A.dylib                     0x0113ae7e objc_exception_throw + 44
2   CoreFoundation                      0x01d85fb1 -[NSException raise] + 17
3   Tests                               0x00027711 -[GHTestCase failWithException:] + 33
4   Tests                               0x0001a0ed -[CaseTest testGetCaseArrayFromJSONArray] + 3293
5   libobjc.A.dylib                     0x0114e663 -[NSObject performSelector:] + 62
6   Tests                               0x00022e19 +[GHTesting runTestWithTarget:selector:exception:interval:reraiseExceptions:] + 450
7   Tests                               0x0001ea90 -[GHTest run:] + 275
8   Tests                               0x000211ea -[GHTestGroup _run:] + 696
9   Tests                               0x00021513 -[GHTestGroup run:] + 130
10  Tests                               0x000211ea -[GHTestGroup _run:] + 696
11  Tests                               0x00021513 -[GHTestGroup run:] + 130
12  Tests                               0x000239a2 -[GHTestRunner runTests] + 257
13  Tests                               0x00023b12 -[GHTestRunner _runInBackground] + 79
14  Foundation                          0x00b85805 -[NSThread main] + 76
15  Foundation                          0x00b85764 __NSThread__main__ + 1304
16  libsystem_c.dylib                   0x983c7557 _pthread_start + 344
17  libsystem_c.dylib                   0x983b1cee thread_start + 34

FAIL (0.033s)
Это было полезно?

Решение

"Type mismatch" is because GHAssertEquals requires that both arguments be the same type. [caseArray count] returns an unsigned integer. This doesn't match 627 which is a signed integer. So instead, compare against an unsigned 627, namely 627U:

GHAssertEquals([caseArray count], 627U, @"array count equals");

Alternatively, you could use OCHamcrest to say

assertThat(caseArray, hasCountOf(627));

(OCHamcrest is compatible with GHUnit.)

Другие советы

I don't know GHAsserEquals, but your expression is equivalent to:

GHAssertEquals([caseArray count], 627, @"array count equals");
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top