3

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.

Mike Clark
  • 10,027
  • 3
  • 40
  • 54
  • My colleagues and I have this same issue whenever we use macros. I think it may just be a huge bug in Xcode. – FreeAsInBeer Jul 22 '11 at 01:06
  • @FreeAsInBeer I am sorry to hear that! I hope someone has a workaround, or maybe Apple will fix it sometime soon. – Mike Clark Jul 22 '11 at 01:20
  • 1
    I'm seeing this, too. It worked great in Xcode 3—surprised it isn't fixed yet. It also affects other sorts of macros where it's more cumbersome to work around. – Michael Tsai Nov 16 '11 at 15:09

1 Answers1

1

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);
Paul.s
  • 38,494
  • 5
  • 70
  • 88
  • As of Xcode 4.2, this still hasn't been resolved. So, I'm accepting your suggestions as an answer, since it's the most reasonable approach to being able to use auto-complete in combination with reasonably readable asserts. – Mike Clark Jan 11 '12 at 00:07