Search code examples
objective-cunit-testingsentestingkit

Xcode completion inside STAssert*() macros


I've started using Xcode4's SenTest unit testing facilities. It's been working pretty well, but ...

Xcode isn't offering code completion suggestions inside STAssert*() macros.

I like to write simple expressions right into the assert, to save keystrokes and screen real estate:

STAssertTrue(mydoc.isInitialized, nil);
STAssertTrue(mydoc.pageCount == 2, nil);

The problem I'm having is that Xcode isn't offering code completion while I'm writing the expression inside the asserts.

This is a big bummer in the context of unit tests, where code completion can be a rapid and convenient way to remind yourself of the remaining properties and methods you need to write asserts for. Not to mention the usual benefits of completion.

So I've taken to writing my asserts like this, so I can get the code completion:

BOOL b = NO;

b = mydoc.isInitialized;
STAssertTrue(b, nil);

b = mydoc.pageCount == 2;
STAssertTrue(b, nil);

I'd really rather not have to do this kind of thing. It's more verbose, it's harder to read, and it makes Xcode's unit test failure messages less meaningful.

Any ideas? I've deleted my derived data dir, rebooted Xcode, cleaned, rebuilt, etc.


Solution

  • Not really an answer but a suggestion:

    You say it makes your code more verbose and harder to read? Why not use meaningful names for your place holder variables and you can possibly increase the readability of your tests e.g.

    BOOL isDocumentInitialized = mydoc.initialized;
    STAssertTrue(isDocumentInitialized, @"myDoc should be initialized");
    
    // You may even wish to change the naming convention on the object method to be
    - (BOOL)isInitialized; // instead of - (BOOL)initialized;
    // It is perhaps slightly clearer and follows other naming conventions 
    
    BOOL hasTwoPages = (2 == mydoc.pageCount);
    STAssertTrue(hasTwoPages, @"myDoc should have 2 pages but has %d pages", mydoc.pageCount);