Objective-C Travis issue for boolean values in XCTAssertEqual: (“NO”) is not equal to (“0”)

here's my test code which succeeds locally:

- (void)setUp {

    restroom = [[Restroom alloc] initWithName:@"Target" andIsAccessible:FALSE andIsUnisex:TRUE];

}

- (void)tearDown {

    restroom = nil;
}

- (void)testThatARestroomCanBeCreated
{
    XCTAssertNotNil(restroom, @"Should be able to create a Restroom instance.");
}

- (void)testThatRestroomHasAName
{
    XCTAssertEqualObjects(restroom.name, @"Target", @"Restroom should have the name given when initialized.");
}

- (void)testThatRestroomHasAFlagForAccessibility
{
    XCTAssertEqual(restroom.isAccessible, FALSE, @"Restroom should have the accessibility flag given when initialized.");
}

- (void)testThatRestroomHasAFlagForUnisex
{
    XCTAssertEqual(restroom.isUnisex, TRUE, @"Restroom should have the unisex flag given when initialized.");
}

however, when Travis processes it, i get error for only the tests relating to boolean values:

 ✗ -[RRiOSAppTests testThatRestroomHasAFlagForAccessibility] (0 ms) (0)
  -[RRiOSAppTests testThatRestroomHasAFlagForUnisex]

/Users/travis/build/.../RRiOSApp/RRiOSAppTests/RRiOSAppTests.m:91: ((restroom.isUnisex) equal to (1)) failed: ("YES") is not equal to ("1") - Restroom should have the unisex flag given when initialized.:

...

✗ -[RRiOSAppTests testThatRestroomHasAFlagForUnisex] (0 ms) (1)
✓ -[RRiOSAppTests testThatRestroomHasAName] (0 ms)

/Users/travis/build/.../RRiOSApp/RRiOSAppTests/RRiOSAppTests.m:86: ((restroom.isAccessible) equal to (0)) failed: ("NO") is not equal to ("0") - Restroom should have the accessibility flag given when initialized.

I tried replacing TRUE and FALSE with 1 and 0 - but the same error came about.

Here's my .travis.yml file:

language: objective-c
install:
    - brew remove --force xctool
    - brew install xctool --HEAD

script:
  - xctool test -project RRiOSApp/RRiOSApp.xcodeproj -scheme RRiOSApp -sdk iphonesimulator7.0

And, I'm using Xcode 6

Answers


BOOL is either YES or NO, not TRUE or FALSE. TRUE is not the same type as YES, which is why the test fails. There is also true, which is a completely different type.

TRUE is defined in Core Foundation as:

#define TRUE 1

YES is defined in the ObjC runtime as:

#define YES (BOOL)1

true is defined differently depending on whether you're compiling as C99 or C++. You can look it up in stdbool.h if you're curious.

But in any case, you shouldn't test equality to BOOL (ever, not just in tests). You should test truth. The tests you want here is XCTAssertTrue and XCTAssertFalse. There are many "true" values that are not equal to YES or TRUE, which is why testing equality on BOOL is error-prone.


Need Your Help

PHP: (PDO) Mysql most effective way to add sting to returned value out of db

php mysql pdo

In a mysql database I store some image names without the exact path.

Save Naive Bayes Trained Classifier in NLTK

python machine-learning classification nltk bayesian

I'm slightly confused in regard to how I save a trained classifier. As in, re-training a classifier each time I want to use it is obviously really bad and slow, how do I save it and the load it again

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.